感谢您抽出宝贵时间阅读本说明。
我有一个XML文件,需要为每个部分声明一个密钥。
<chapter>
<section> First section
<section>Section 1</section>
<section>Section 2</section>
<section>Section 3
<informaltable role="table">
<thead>
<row>
<entry>Familly</entry>
<entry>Type</entry>
</row>
</thead>
<tbody>
<row>
<entry>F1</entry>
<entry>T1</entry>
</row>
<row>
<entry>F1</entry>
<entry>T2</entry>
</row>
</tbody>
</informaltable>
</section>
</section>
<section> Seconde section
<section>Section 1</section>
<section>Section 2</section>
<section>Section 3
<informaltable role="table">
<thead>
<row>
<entry>Familly</entry>
<entry>Type</entry>
</row>
</thead>
<tbody>
<row>
<entry>F2</entry>
<entry>T2</entry>
</row>
<row>
<entry>F1</entry>
<entry>T2</entry>
</row>
</tbody>
</informaltable>
</section>
</section>
</chapter>
现在我已经定义了这样的键
<xsl:key name="byFamilly" match="d:chapter/d:section[1]//d:row" use="d:entry[1]"/>
<xsl:key name="byFamilly" match="d:chapter/d:section[2]//d:row" use="d:entry[1]"/>
节数大于50的情况可以声明一个键各个区域的不同值。
谁能帮我解决这个问题。
谢谢。
XSLT 1中的常用技术是将祖先生成的ID(即section
)插入键值,例如
<xsl:key name="byFamilly" match="d:chapter/d:section//d:row" use="concat(generate-id(ancestor::d:section), '|', d:entry[1])"/>
在XSLT 2和更高版本中,
key
函数具有可选的第三个参数,您可以在其中传递您希望将查找限制为section
的位置,因此您无需在键值中包含id。