You are on page 1of 3

<Category>Officer</Category>

<?xml version="1.0" encoding="UTF-8"?> <Age>40</Age>


</Employee>
<!-- <?xml-stylesheet type="text/xsl" href="cadre_declarative.xsl"? <Employee id="08" salary="20000">
> --> <FirstName>Joe</FirstName>
<LastName>Dalton</LastName>
<Company> <Position>Chief Evasion Officer</Position>
<Employee id="01" salary="10000"> <Email>Chief@Dalton.com</Email>
<FirstName>Tim</FirstName> <Category>President</Category>
<LastName>Browne</LastName> <Age>31</Age>
<Position>CEO</Position> </Employee>
<Email>TBrowne@Infoteria.com</Email> <Employee id="09">
<Category>Officer</Category> <FirstName>Averell</FirstName>
<Age>25</Age> <LastName>Dalton</LastName>
</Employee> <Position>Tall Evasion Officer</Position>
<Employee id="02"> <Email>Averell@Dalton.com</Email>
<FirstName>David</FirstName> <Category>Officer</Category>
<LastName>Silverlight</LastName> <Age>25</Age>
<Position>Chief XML Evangelist</Position> </Employee>
<Employee id="10">
<FirstName>Rantan</FirstName>
<Email>HeadGeek@XMLPitstop.com</Email>
<LastName>Plan</LastName>
<Category>Evangelist</Category>
<Position>Watchdog</Position>
<Age>30 </Age>
<Email>RPlan@waouf.com</Email>
</Employee>
<Category>Guardian</Category>
<Employee id="03" salary="6000">
<Age>10</Age>
<FirstName>Mike</FirstName>
</Employee>
<LastName>Damphouse</LastName>
</Company>
<Position>Chief Marketing Officer
</Position>
Ecrivez les expressions XPath qui retournent
<Email>MDamphouse@Infoteria.com</Email> 1. les noeuds 'Employee'
<Category>Officer</Category>
<Age>31</Age> /descendant::Employee
</Employee> //Employee
<Employee id="04"> //child::Employee
<FirstName>Todd</FirstName>
<LastName>Headrick</LastName> /Company/Employee
<Position>Chief Technology
Officer</Position>
<Email>Theadrick@Infoteria.com</Email>
<Category>Officer</Category> 2. les emails
<Age>33</Age>
</Employee> //Email
<Employee id="05" salary="7000"> /Company/Employee/Email
<Age>35</Age>
<FirstName>Lilly</FirstName> 3. les salaires
<LastName>Rose</LastName>
<Position>President of //@salary
Operations</Position> //*/@salary
<Email>LRose@xmlcom</Email> //Employee/@salary
<Category>President</Category> //Employee/attribute::salary
</Employee> /Company/Employee/@salary
<Employee id="06">
<FirstName>Timm</FirstName> mettre des @salary dans d'autres ÈlÈments
<LastName>Cok</LastName>
<Position>CEO</Position> 4. le nombre d'employÈs
<Email>tcok@apple.com</Email>
<Category>President</Category> count(//Employee)
<Age>55</Age>
</Employee> 5. le deuxiËme employÈ
<Employee id="07">
<FirstName>John</FirstName> //Employee[position()=2]
<LastName>Wayne</LastName> //Employee[2]
<Position>Problem solver</Position>
<Email>Cowboy@XML.com</Email> attention ‡ : $x("//Employee")[1]
(substring(substring-after(Email,'@'),1+string-
length(LastName),1)='.')]
6. les 3 premiers employÈs
//Employee[position() < 4] //Employee[concat(LastName,'.com') = substring-after(Email,'@')]

7. lí‚ge de líemployÈ ayant líidentifiant '06'


//Employee[attribute::id='06']/child::Age
$x("//Employee[LastName=substring(Email,string-length(Email)-3-
//Employee[attribute::id='06']/Age
string-length(LastName),string-length(LastName))]")
//Employee[@id='06']/Age
//Employe[LastName = substring(Email,'@',length(LastName)]
//Age[../@id='06']
//Age[parent::*/@id='06']
13. le dernier noeud fils de l'avant dernier noeud
8. lí‚ge de líemployÈ 'Wayne' 'Employee'
//Employee[LastName='Wayne']/Age
//Employee[LastName/text()='Wayne']/Age //Employee[position()=last()-1]/*[last()]
//Employee[last()-1]/*[last()]
//LastName[.='Wayne']/../Age //Employee[last()-1]/child::*[last()]
//LastName[self::*='Wayne']/parent::*/Age //Employee[position()=last()-1]/child::*[position()=last()]
//LastName[self::*='Wayne']/parent::Employee/Age //Employee[position()=last()-1]/node()[position()=last()]

//Age[../LastName='Wayne'] //Employee[count(//Employee)-1]/*[last()]
//Employee[count(//Employee)-1]/*[count(../*)]
//LastName[self::*='Wayne']/following-sibling::Age
//LastName[.='Wayne']/following-sibling::Age //Employee[last()]/preceding-sibling::*[1]/*[last()]

9. les noms des employÈes dont la catÈgorie est 'Officer' (//Employee/*[last()])[last()-1]

//Employee[Category='Officer']/LastName
14. les employÈs plus jeunes que 30 ans
//Category[.='Officer']/preceding-sibling::LastName
//Employee[Age<30]
//LastName[following-sibling::Category='Officer']
15. la somme des salaires
10. les employÈs dont la longueur du prÈnom est díau sum(//@salary)
moins 4 caractËres sum(//*/@salary)
sum(//Employee/@salary)
//Employee[string-length(FirstName) >3]
16. líemployÈ aprËs John Wayne
//FirstName[string-length(.)>3]/..
//Employee[LastName='Wayne' and FirstName='John' ]/following-
sibling::Employee[1]
11. les employÈs dont le poste (Position) contient 'Chief'
//Employee[contains(Position,'Chief')]
//Employee[contains(Position/text(),'Chief')] //Employee[count(//Employee[LastName='Wayne']/preceding-
sibling::*)+2]
//Employee/Position[contains(text(),'Chief')]/parent::Employee
//Employee/Position[contains(.,'Chief')]/parent::Employee //Employee[position()=//Employee[FirstName='John']
//Employee/Position[contains(.,'Chief')]/.. [LastName='Wayne']/@id + 1]

//Position[contains(.,'Chief')]/parent::Employee 17. la position de líemployÈ Wayne


//Position[contains(.,'Chief')]/.. count(//Employee[LastName='Wayne']/preceding-sibling::*)+1

12. les employÈs dont le nom est le mÍme que le domaine


de leur email Declarative
<?xml version="1.0" encoding="utf-8"?>
//Employee[contains(substring-after(Email,'@'), LastName)] <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
//Employee[LastName=substring-before(substring- <xsl:output method="html"/>
after(Email,'@'),'.')]
<xsl:template match="LastName">
//Employee[contains(Email, concat('@',LastName))]
<span color="blue">
//Employee[(substring(substring-after(Email,'@'),1,string-
<xsl:value-of
length(LastName))=LastName)
select="preceding-sibling::FirstName"/>
and
<xsl:text> </xsl:text> <xsl:output method="html"/>
<xsl:value-of
select="."/>
<xsl:template match="/">
<html>
</span>
<head>
</xsl:template>
<title>XSLT Excercises</title>
</head>
<xsl:template match="/">
<body bgcolor="beige">
<html>
<head>
<title>XSLT Excercises</title> <H1>Company Information for Infoteria</H1>
</head> <H2>Employee Listing</H2>
<body bgcolor="beige"> <table border="1">
<tr>
<th>Name</th>
<H1>Company Information for Infoteria</H1>
<th>Position</th>
<H2>Employee Listing</H2>
<th>E-mail</th>
<table border="1">
</tr>
<tr>
<xsl:for-each select="//Employee">
<th>Name</th>
<xsl:sort select="substring-after(Email,'@')"/>
<th>Position</th>
<th>E-mail</th>
</tr> <tr>
<td>
<xsl:apply-templates <xsl:value-of select="child::LastName"/>
select="//Employee"/> <xsl:text> </xsl:text>
</table> <xsl:value-of select="FirstName"/>
<p>Total Number Employees: <xsl:value-of </td>
select="count(//Employee)"/> </p> <td><xsl:value-of select="Position"/></td>
</body> <td><xsl:value-of select="Email"/></td>
</html> </tr>
</xsl:template>
</xsl:for-each>

<xsl:template match="Employee">
</table>
<p>Total Number Employees: <xsl:value-of
<tr> select="count(//Employee)"/> </p>
<td> </body>
<xsl:apply-templates </html>
select="LastName"/> </xsl:template>
</td>
<td>
</xsl:stylesheet>
<xsl:apply-templates
select="Position"/>
</td>
<td>
<xsl:value-of
select="Email"/>
</td>
</tr>

</xsl:template>

</xsl:stylesheet>

Imperative

<?xml version="1.0" encoding="utf-8"?>


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

You might also like