在 XSLT 中声明多个键
Declaring multiples Keys in XSLT
提前感谢您花时间阅读本文。
我有一个 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
可以声明one key大陆每个section的不同值
谁能帮我看看怎么做。
谢谢。
XSLT 1 中的常用技术是在键值中插入从祖先(即 section
)生成的 ID,例如
<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在键值中。
提前感谢您花时间阅读本文。
我有一个 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 可以声明one key大陆每个section的不同值
谁能帮我看看怎么做。
谢谢。
XSLT 1 中的常用技术是在键值中插入从祖先(即 section
)生成的 ID,例如
<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在键值中。