1
Я пытаюсь выяснить, как получить многопозиционное (1.1) узла при назначении ключам. Ниже урезанная воспроизведение выпуска:using xsl: number with xsl: key, чтобы получить позицию узла
Входной XML:
<doc>
<chapter>
<title>Chapter</title>
<section>
<para0>
<title>section</title>
</para0>
</section>
<section>
<para0>
<title>section</title>
</para0>
</section>
<procedure>
<title>procedure</title>
</procedure>
<section>
<para0>
<title>section</title>
</para0>
</section>
<section>
<para0>
<title>section</title>
</para0>
</section>
<procedure>
<title>procedure</title>
</procedure>
</chapter>
</doc>
Желаемая выход
<output>
<chapter>Chapter 1
<section>section 1.1</section>
<section>section 1.2</section>
<section>procedure 1.3</section>
<section>section 1.4</section>
<section>section 1.5</section>
<section>procedure 1.6</section>
</chapter>
</output>
выходной ток
<output>
<chapter>Chapter 1
<section>section 1</section>
<section>section 1</section>
<section>procedure 1</section>
<section>section 1</section>
<section>section 1</section>
<section>procedure 1</section>
</chapter>
</output>
Мой XSLT
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="numbering" match="chapter/procedure" use="generate-id()"/>
<xsl:key name="numbering" match="chapter/section/para0" use="generate-id()" />
<xsl:template match="/">
<output>
<xsl:apply-templates/>
</output>
</xsl:template>
<xsl:template match="doc">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="chapter">
<chapter>
<xsl:value-of select="title"/>
<xsl:text> </xsl:text>
<xsl:number level="multiple" count="chapter" format="1"/>
<xsl:for-each select="section/para0 | procedure ">
<section>
<xsl:value-of select="title"/>
<xsl:text> </xsl:text>
<xsl:number level="any" select="key('numbering', generate-id())/title" from="chapter" format="1.1"/>
</section>
</xsl:for-each>
</chapter>
</xsl:template>