Mam nastepujący problem . Zalozmy ze mam nastepujacy dokument z moim meta
jezykiem :
<metalanguagae> <ara> some content </para> <heading level="1"> qwerty</heading> <heading level="3">qwerty2</heading> <ara>fasdfas</para> <sth>fdaf<s/th> <heading level="1">qwerty3</heading> </metalanguage>
Pisze do niego transformacje , ktora przeksztalca go na XHTML w taki sposob ze
element <heading level="1"> przechodzi na <h1> itd.
Jednak zalezy mi z pewnych wzgledow zeby do kazdego wynikowego <h1> ,<h2> itd
dodwac atrybut id ktory zawiera liczbe wskazujaca na to ktory to element
heading czyli :
XHTML:
jak to zrobic w XSL'u ?
Znalezlem jakis wzorzec na iteracje ale on sie nie sprawdza do numeracji tych
samych elementow. Potem probowalem w ten sposob :
xsl:template match="heading"> <xsl:choose> <xsl:when >test='@level="1"'> <h1> <xsl:attribute name="id"> <xsl:text>toc</xsl:text> <xsl:number value="position() - 1" format="1" /> </xsl:attribute> <xsl:apply-templates /> </h1> </xsl:when> <xsl:when >test='@level="2"'> <h2> <xsl:attribute name="id"> <xsl:text>toc</xsl:text> <xsl:number value="position() - 1" format="1" /> </xsl:attribute> <xsl:apply-templates /> </h2> </xsl:when> <xsl:when >test='@level="3"'> <h3> <xsl:attribute name="id"> <xsl:text>toc</xsl:text> <xsl:number value="position() - 1" format="1" /> </xsl:attribute> <xsl:apply-templates /> </h3> </xsl:when> <xsl:when >test='@level="4"'> <h4> <xsl:attribute name="id"> <xsl:text>toc</xsl:text> <xsl:number value="position() - 1" format="1" /> </xsl:attribute> <xsl:apply-templates /> </h4> </xsl:when> <xsl:when >test='@level="5"'> <h5> <xsl:attribute name="id"> <xsl:text>toc</xsl:text> <xsl:number value="position() - 1" format="1" /> </xsl:attribute> <xsl:apply-templates /> </h5> </xsl:when> <xsl:when >test='@level="6"'> <h6> <xsl:attribute name="id"> <xsl:text>toc</xsl:text> <xsl:number value="position() - 1" format="1" /> </xsl:attribute> <xsl:apply-templates /> </h6> </xsl:when> </xsl:choose> </xsl:template>
Okazal sie byc on prawie dobry ale XPath'owe position() zwraca pozycje w
strukturze dokumentu a nie w odniesieniu do tych samych elementow i w ten
sposob liczby jakie sa przyporzadkowywane nie sa kolejnymi liczbami
naturalnymi
Czy ktos ma jakis pomysl jak to zrobic ?