Xml 如何将有限多映射为具有优先级的1
我的输入文档具有有限数量的可能值。需要将这些值作为聚合读取,并将现有的最高优先级作为单个值报告。例如: 如果我可能的输入标签是:(但并非所有标签都始终存在,并且订单也不会被挂载)Xml 如何将有限多映射为具有优先级的1,xml,xslt-2.0,xpath-2.0,Xml,Xslt 2.0,Xpath 2.0,我的输入文档具有有限数量的可能值。需要将这些值作为聚合读取,并将现有的最高优先级作为单个值报告。例如: 如果我可能的输入标签是:(但并非所有标签都始终存在,并且订单也不会被挂载) A B C D 我的优先级是A,然后是B,然后是C,然后是D。在这种情况下,我希望我的输出是: <SomeOutput>A</SomeOutput> A 在下列情况下: <SomeInput>D</SomeInput> <SomeInput>B</
A
B
C
D
我的优先级是A,然后是B,然后是C,然后是D。在这种情况下,我希望我的输出是:
<SomeOutput>A</SomeOutput>
A
在下列情况下:
<SomeInput>D</SomeInput>
<SomeInput>B</SomeInput>
D
B
应产生:
<SomeOutput>B</SomeOutput>
<SomeOutput>B</SomeOutput>
B
提前感谢使用:
/*/*[. eq min(/*/*/string())][1]
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*/*[. eq min(/*/*/string())][1]" priority="2">
<someOutput><xsl:apply-templates/></someOutput>
</xsl:template>
<xsl:template match="/*/*"/>
</xsl:stylesheet>
这是一个完整的转换:
/*/*[. eq min(/*/*/string())][1]
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*/*[. eq min(/*/*/string())][1]" priority="2">
<someOutput><xsl:apply-templates/></someOutput>
</xsl:template>
<xsl:template match="/*/*"/>
</xsl:stylesheet>
当此转换应用于以下XML文档时(提供的片段,包装成单个顶部元素,使其成为格式良好的XML文档):
A.
B
C
D
生成所需的正确结果:
<SomeOutput>A</SomeOutput>
<t>
<SomeInput>D</SomeInput>
<SomeInput>B</SomeInput>
</t>
A
在此XML文档上应用相同转换时:
<SomeOutput>A</SomeOutput>
<t>
<SomeInput>D</SomeInput>
<SomeInput>B</SomeInput>
</t>
D
B
再次生成所需的正确结果:
<SomeOutput>A</SomeOutput>
<t>
<SomeInput>D</SomeInput>
<SomeInput>B</SomeInput>
</t>
B