|
|
Posizionare la funzione
|
La funzione �di posizione� ritorni il numero uguale alla posizione di contesto e �l'ultima� funzione ritorni il numero uguale al formato di contesto da un contesto di valutazione di espressione. Lo stylesheet 1 di XSL dimostra l'uso di queste due funzioni in vari dei contesti.
|
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>
|
|
Funzione di conteggio
|
Una funzione di conteggio restituisce il numero di nodi presenti in una discussione nodo-si � regolata.
|
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>
|
|
Funzione di identificazione
|
Una funzione �dell'identificazione� seleziona gli elementi dalla loro identificazione che � unica. Lo stylesheet 1 di XSL mostra gli esempi semplici del relativo 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>
|
|
Locale-nome & funzione Namespace-uri
|
�Il locale-nome� e �namespace-uri ()� sono usati per ottenere le informazioni sui nomi di attributo e dell'elemento e sui 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
|