|
|
Posicionar a fun��o
|
A fun��o da �posi��o� retornos o n�mero igual � posi��o do contexto e a ��ltima� fun��o retornos o n�mero igual ao tamanho do contexto de um contexto da avalia��o da express�o. O stylesheet 1 de XSL demonstra o uso destas duas fun��es em diversos dos contextos.
|
XML Source
<source>
<AAA>
<BBB>
<CCC>Carl</CCC>
</BBB>
<BBB/>
<BBB/>
</AAA>
<AAA>
<BBB/>
<BBB>
<CCC>John</CCC>
<CCC>Charles</CCC>
<CCC>Robert</CCC>
<CCC>Anthony</CCC>
</BBB>
</AAA>
</source>
|
Output
<DIV>BBB(1/5)(2/5)(3/5)(4/5)(5/5)</DIV>
<DIV>CCC(1/5)(2/5)(3/5)(4/5)(5/5)</DIV>
<DIV>CCC(1/4)(2/4)(3/4)(4/4)</DIV>
|
|
XSL stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<DIV>
<xsl:for-each select="//BBB">
<xsl:call-template name="printout"/>
</xsl:for-each>
</DIV>
<DIV>
<xsl:apply-templates select="//CCC"/>
</DIV>
<DIV>
<xsl:apply-templates select="//AAA[last()]//CCC"/>
</DIV>
</xsl:template>
<xsl:template match="CCC">
<xsl:call-template name="printout"/>
</xsl:template>
<xsl:template name="printout">
<xsl:if test="position()=1">
<xsl:value-of select="name()"/>
</xsl:if>
<xsl:text>(</xsl:text>
<xsl:value-of select="position()"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="last()"/>
<xsl:text>)</xsl:text>
</xsl:template>
</xsl:stylesheet>
|
|
Fun��o da contagem
|
Uma fun��o da contagem retorna o n�mero dos n�s atuais em um argumento n�-ajustou-se.
|
XML Source
<source>
<AAA>
<CCC/>
<BBB>
<CCC>Carl</CCC>
</BBB>
<BBB/>
<BBB/>
</AAA>
<AAA>
<CCC/>
<BBB/>
<BBB>
<CCC>John</CCC>
<CCC>Charles</CCC>
<CCC>Robert</CCC>
<CCC>Anthony</CCC>
</BBB>
</AAA>
</source>
|
Output
<DIV>
<B>//AAA : </B>2</DIV>
<DIV>
<B>//CCC : </B>7</DIV>
<DIV>
<B>//AAA/CCC : </B>2</DIV>
<DIV>
<B>//CCC[text()]) : </B>5</DIV>
|
|
XSL stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<DIV>
<B>
<xsl:text>//AAA : </xsl:text>
</B>
<xsl:value-of select="count(//AAA)"/>
</DIV>
<DIV>
<B>
<xsl:text>//CCC : </xsl:text>
</B>
<xsl:value-of select="count(//CCC)"/>
</DIV>
<DIV>
<B>
<xsl:text>//AAA/CCC : </xsl:text>
</B>
<xsl:value-of select="count(//AAA/CCC)"/>
</DIV>
<DIV>
<B>
<xsl:text>//CCC[text()]) : </xsl:text>
</B>
<xsl:value-of select="count(//CCC[text()])"/>
</DIV>
</xsl:template>
</xsl:stylesheet>
|
|
Fun��o do ID
|
Uma fun��o da �identifica��o� seleciona os elementos por seu ID que � original. O stylesheet 1 de XSL mostra exemplos simples de seu uso.
|
XML Source
<!DOCTYPE source [
<!ELEMENT chapter ANY>
<!ATTLIST chapter id ID #REQUIRED>
<!ELEMENT title ANY>
<!ATTLIST title id CDATA #REQUIRED>
<!ELEMENT text ANY>
<!ATTLIST text value ID #REQUIRED>
]>
<source>
<chapter id="intro">Introduction</chapter>
<chapter id="body">
<title id="t1">BODY</title>
<text value="text1">text text text</text>
</chapter>
<chapter id="end">THE END</chapter>
</source>
|
Output
<P>Introduction</P>
<P>text text text</P>
<P>text text text</P>
|
|
XSL stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<P>
<xsl:value-of select="id('intro')"/>
</P>
<P>
<xsl:value-of select="id('body')/text"/>
</P>
<P>
<xsl:value-of select="id('text1')"/>
</P>
</xsl:template>
</xsl:stylesheet>
|
|
Local-nome & fun��o Namespace-uri
|
O �local-nome� e �namespace-uri ()� s�o usados come�ar as informa��es sobre os nomes do elemento e do atributo e os namespaces.
|
XML Source
<source xmlns:zvon="http://zvon.org/" xmlns:ict="XXX" >
<zvon:id>ZvonAAA</zvon:id>
<zvon:size>258</zvon:size>
<ict:id>ICT1258</ict:id>
</source>
|
Output
<TABLE border="1">
<TR>
<TH>name</TH>
<TH>local</TH>
<TH>URI</TH>
</TR>
<TR>
<TD>source</TD>
<TD>source</TD>
<TD/>
</TR>
<TR>
<TD>zvon:id</TD>
<TD>id</TD>
<TD>http://zvon.org/</TD>
</TR>
<TR>
<TD>zvon:size</TD>
<TD>size</TD>
<TD>http://zvon.org/</TD>
</TR>
<TR>
<TD>ict:id</TD>
<TD>id</TD>
<TD>XXX</TD>
</TR>
</TABLE>
|
|
XSL stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<TABLE border="1">
<TR>
<TH>name</TH>
<TH>local</TH>
<TH>URI</TH>
</TR>
<xsl:apply-templates select="//*"/>
</TABLE>
</xsl:template>
<xsl:template match="*">
<TR>
<TD>
<xsl:value-of select="name()"/>
</TD>
<TD>
<xsl:value-of select="local-name()"/>
</TD>
<TD>
<xsl:value-of select="namespace-uri()"/>
</TD>
</TR>
</xsl:template>
</xsl:stylesheet>
|
|
|
|
Keywords xsl sort, xsl element, xsl xpath, xsl examples, xsl example, xsl param, xsl select,
xsl template, xsl syntax, xsl text, xpath node, xsl parameter, xsl javascript,
xsl document, xsl id, xsl date, select function, javascript node, string xsl,
element node, xsl stylesheet, value xsl, javascript function, node attributes,
name node, value function, node child, node examples, expression function, xsl tag,
function variables, document node, variable function, text node, node attribute,
string function, select node, node tag, text function, xsl using
|