Name1 Value1
Name1 Value2
Name1 Value3
Name1 Value4
Name2 Value5
Name2 Value6
Name2 Value7
我需要在报告中输出:
-Name1
--Value1
--Value2
--Value3
--Value4
-Name2
--Value5
--Value6
--Value7
我需要在类似php的XSL中做到这一点:
$x_key= '';
foreach($arr as $key=>$value)
{
if ($x_key != $key) {
$x_key = $key;
echo "-$key\n";
}
echo "--$value\n";
}
我的代码可能是(但不要按我想要的那样做):
<xsl:variable name="NAMEOLD" select="X" />
<xsl:for-each select="//ROWSET1_ROW[position()]">
<xsl:variable name="NAME" select="NAME_NUMBER" />
<xsl:choose>
<xsl:when test="NAME!=NAMEOLD">
<xsl:variable name="NAMEOLD" select="NAME" />
<fo:table-row>
<fo:table-cell xsl:use-attribute-sets="cell-transparent" >
<fo:block xsl:use-attribute-sets="align-left txt" keep-together.within-page="always">
<xsl:value-of select="NAME_NUMBER"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:when>
</xsl:choose>
<fo:table-row>
<fo:table-cell xsl:use-attribute-sets="cell-transparent" >
<fo:block xsl:use-attribute-sets="align-left txt" keep-together.within-page="always">
<xsl:value-of select="VALUE"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
感谢任何线索或答案 Stoupa101
答案 0 :(得分:0)
您尚未显示输入XML。最简单的解决方案是以下几行(注意这需要XSLT 2.0):
<xsl:for-each-group select="ROW" group-adjacent="name">
<h1><xsl:value-of select="current-grouping-key"></h1>
<xsl:for-each select="current-group()"/>
<p><xsl:value-of select="value"/></p>
</xsl:for-each-group>
不要试图以PHP的方式去做 - 当你使用高级语言时,编写低级代码毫无意义。