【发布时间】:2021-02-04 09:47:37
【问题描述】:
我需要我的 xml 输出,但是输出 xml 是基于来自输入值的条件。 输出 xml 不是输入 xml 的转换。 xml 位于另一个由文档函数访问的变量中。在这里,我使用文档函数在 xslt 中使用了 xml。
文档函数访问的xml 有id 属性,其值按升序排列。输入是一个数字(比如来自输入 xml),该数字应与从顶部选择元素开始访问的 xml 文档的 id 属性进行比较。如果在任何情况下对应的值(id 属性 + 15)大于输入数字,则应从输出 xml 中忽略特定的选择元素和前面的选择元素。
例如,如果输入数字为 100,则输出应如下所示,因为满足条件的第一个元素是 id 值“90”。因为 90 +15 大于 100。
<menu>
<choice id="95">C</choice>
<choice id="100">C</choice>
</menu>
我的输入 xml 是说
<a>100</a>
我的 xslt 输出所有内容
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="my:my">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<my:elements>
<menu>
<choice id="20">ABC</choice>
<choice id="23">B</choice>
<choice id="30">C</choice>
<choice id="37">C</choice>
<choice id="45">C</choice>
<choice id="50">C</choice>
<choice id="90">C</choice>
<choice id="95">C</choice>
<choice id="100">C</choice>
</menu>
</my:elements>
<xsl:template match="/">
<xsl:copy-of select="document('')/*/my:elements/*"/>
</xsl:template>
</xsl:stylesheet>
【问题讨论】: