【发布时间】:2014-09-17 03:09:47
【问题描述】:
我有一个这样的 XML
<Ozellik isim="Renk-Beden">STANDART STD</Ozellik>
<Ozellik isim="Grup">ADMIN</Ozellik>
<Ozellik isim="Amac">DENEME</Ozellik>
<Ozellik isim="BlaBla">BLABLA</Ozellik>
并希望将其转换为 this 并限制为三个元素。如果超过 3 条记录,取前 3 条记录
<property1 name="Renk-Beden">STANDART STD</property1>
<property2 name="Grup">ADMIN</property2>
<property3 name="Amac">DENEME</property3>
我尝试了许多 xslt 代码,但无法将其转换为所需的输出。谢谢你的帮助。
我最后一次成功的尝试是:
<xsl:template name="loop">
<xsl:param name="pCount"/>
<xsl:param name="pValue"/>
<xsl:param name="pAtt"/>
<xsl:element name="property{$pCount}">
<xsl:attribute name="name">
<xsl:value-of select="$pAtt" />
</xsl:attribute>
<xsl:value-of select="$pValue" />
</xsl:element>
</xsl:template>
<xsl:template match="Ozellik">
<xsl:param name="pCount" select="0"/>
<xsl:for-each select="catalog/cd">
<xsl:call-template name="loop">
<xsl:with-param name="pCount" select="position()" />
<xsl:with-param name="pValue" select="." />
<xsl:with-param name="pAtt" select="@isim" />
</xsl:call-template>
</xsl:for-each>
</xsl:template>
【问题讨论】:
-
I tried many xslt codes,你能发布你的最后一次尝试吗? -
我添加了我的最后一次尝试
-
你为什么选择
catalog/cd,你提供的样本输入中没有元素catalog或cd