gpt4 book ai didi

java - 如何使用 XSL 排列数据

转载 作者:行者123 更新时间:2023-11-30 02:13:03 26 4
gpt4 key购买 nike

My XSL-

<xsl:template match="Identity" mode="Insureds">
X : <xsl:value-of select="X"/>
Y : <xsl:value-of select="Y"/>
</xsl:template>

My XML-

<A identity="1">
<X>P</X>
<Y>R</Y>
</A>
<A identity="2">
<X>Q</X>
<Y>R</Y>
</A>

这里只有 2 个循环是可能的,并且“Y”的值(如果存在)将与两个循环中的“R”相同。

嗨,我需要使用 xsl 打印数据。如果有两个循环,问题就出在这里它打印像

X : P
Y : R
X : Q
Y : R

但我需要像下面这样

X : P
Q
Y : R

最佳答案

听起来像是可以在 XSLT 2 或 3 中解决的分组问题(Saxon 9 在 Java 中支持),使用

  <xsl:template match="root">
<xsl:for-each-group select="A/*" group-by="node-name()">
<xsl:value-of select="current-grouping-key() || ' : '"/>
<xsl:for-each-group select="current-group()" group-by=".">
<xsl:value-of select="."/>
<xsl:text>&#10;</xsl:text>
</xsl:for-each-group>
</xsl:for-each-group>
</xsl:template>

https://xsltfiddle.liberty-development.net/bFDb2BJ/1

关于java - 如何使用 XSL 排列数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49553786/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com