|
|
Os machados de XSL
|
Os machados jogam o papel muito importante em XSL. Todos os machados s�o usados no exemplo dado abaixo
|
XML source
<?xml version="1.0"?>
<xslTutorial >
<doc>
<ancprec>
<p>Preceeding Ancestor. <br/></p>
</ancprec>
<gf>
<p>Ancestor. <br/></p>
<pprec choice="a">
<p>Preceeding Parent.<br/> </p>
</pprec>
<par>
<p>Parent. <br/></p>
<sibprec>
<p>Preceeding sibling.<br/> </p>
</sibprec>
<me id="id001">
<p>Me.<br/> </p>
<!-- Comment after Me -->
<chprec >
<p>Preceeding child.<br/> </p >
</chprec>
<child idref="id001">
<p>Child. <br/></p>
<?pi Processing Instruction ?>
<dprec>
<p>preceeding Descendant.<br/> </p>
</dprec>
<desc>
<p>Descendant.<br/> </p>
</desc>
<dfoll>
<p>Following Descendant.<br/> </p>
</dfoll>
</child>
<chfoll>
<p>following child.<br/> </p>
</chfoll>
</me>
<sibfoll>
<p>Following Sibling.<br/> </p>
</sibfoll>
</par>
<pfoll>
<p>Following Parent.<br/> </p>
</pfoll>
</gf>
<ancfoll>
<p>following Ancestor.<br/></p>
</ancfoll>
</doc>
</xslTutorial>
|
|
HTML output 1
<HTML>
<HEAD> </HEAD>
<BODY>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Document</title> </head>
<body>
<H2>Following Axis</H2>
<b>Following Sibling.
<br> Following Parent.
<br> following Ancestor.
<br> </b>
<H2>Descendant or Self Axis</H2>
<b>Me.
<br> Preceeding child.
<br> Child.
<br>preceeding Descendant.
<br> Descendant.
<br> Following Descendant.
<br> following child.
<br> </b>
<H2>Descendant Axis</H2>
<b>Preceeding child.
<br> Child.
<br>preceeding Descendant.
<br> Descendant.
<br> Following Descendant.
<br> following child.
<br> </b>
<H2>Self Axis</H2>
<b>Me.
<br> </b>
<H2>Child Axis</H2>
<b>Preceeding child.
<br> Child.
<br>following child.
<br> </b>
<H2>Following Axis</H2>
<p>
<b>Following Sibling.
<br> Following Parent.
<br> following Ancestor.
<br> </b>
<br>
<i>Note the lack of ancestors here?
<br>Learned anything about document order yet?</i> </p>
<H2>Following Sibling Axis</H2>
<b> Following Sibling.
<br> </b>
<H2>Attribute Axis</H2>
<b>id001</b>
<H2>Parent Axis</H2>
<b>Parent.
<br> </b>
<H2>Ancestor or Self Axis</H2>
<b>Ancestor.
<br>Parent.
<br>Me.
<br> </b>
<H2>Ancestor Axis</H2>
<b>Ancestor.
<br>Parent.
<br> </b>
<H2>Preceding Sibling Axis</H2>
<b>Preceeding sibling.
<br> </b>
<H2>Preceeding Axis</H2>
<b>
<i>Not Implemented in XT 22 09 99</i></b>
<H2>Namespace Axis</H2>
<b>
<i>Not Implemented in XT 22 09 99</i></b>
</body>
</html>
</BODY>
</HTML>
|
|
XSL stylesheet 1
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' >
<xsl:template match="/">
<!-- Lesson. Note how the initial context node
is reduced by the apply templates; this stops
the 'leaking' of content when all I want is
a subset of the whole in the result tree -->
<xsl:apply-templates select="//me"/>
</xsl:template>
<xsl:template match="br">
<br />
</xsl:template>
<xsl:template match="me" priority="10">
<html>
<head>
<title> <xsl:text> Document</xsl:text> </title>
</head>
<body>
<H2>Following Axis</H2>
<b><xsl:apply-templates select="following::*/p"/></b>
<H2>Descendant or Self Axis</H2>
<b><xsl:apply-templates select="descendant-or-self::*/p"/></b>
<H2>Descendant Axis</H2>
<b><xsl:apply-templates select="descendant::*/p"/></b>
<H2>Self Axis</H2>
<b><xsl:apply-templates select="self::*/p"/></b>
<H2>Child Axis</H2>
<b><xsl:apply-templates select="child::*/p"/></b>
<H2>Following Axis</H2>
<p><b><xsl:apply-templates select="following::*/p"/></b>
<br /><i>Note the lack of ancestors here? <br />Learned anything
about document order yet?</i></p>
<H2>Following Sibling Axis</H2>
<b><xsl:apply-templates select="following-sibling::*"/></b>
<H2>Attribute Axis</H2>
<b>
<H2>Parent Axis</H2>
<b><xsl:apply-templates select="parent::*/p"/></b>
<H2>Ancestor or Self Axis</H2>
<b><xsl:apply-templates select="ancestor-or-self::*/p"/></b>
<H2>Ancestor Axis</H2>
<b><xsl:apply-templates select="ancestor::*/p"/></b>
<H2>Preceding Sibling Axis</H2>
<b><xsl:apply-templates select="preceding-sibling::*/p"/></b>
<H2>Preceeding Axis</H2>
<b><i>Not Implemented in XT 22 09 99</i></b>
<H2>Namespace Axis</H2>
<b><i>Not Implemented in XT 22 09 99</i></b>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
|
|
A linha central da crian�a:: pode ser seja omitido da etapa da posi��o porque � uma linha central do defeito. O atributo da linha central:: pode ser o abbreviatet ao @. // � um short para /descendant-or-self:: . � o short para o self:: e. � o short para o pai::.
|
|
|
Keywords xsl templates, xsl include, xsl html, xsl id, xsl parent, xsl date, xsl child, xsl copy,
xsl output, xsl fop, xsl dom, xsl fo, docbook xsl, c# xsl, xsl number, xsl transformation,
xsl tree, svg xsl, xsl current, xalan xsl, msxml xsl, xsl empty, string xsl, xsl tag,
value xsl, display xsl, xsl set, xsl using, xsl generate, convert xsl, xsl multiple,
xsl call, multiple axes, xml axis, xslt axis, xsl axis,
|