[英]xslt to transform format of xml document
i have the xml in a structure such as this: 我有这样的结构中的XML:
<RWFCriteria reportType="ProgramReview">
<item id="36" name="" value="9" type="Milestone" />
<item id="31" name="" value="9" type="Milestone" />
<item id="33" name="" value="11" type="Milestone" />
</RWFCriteria>
and need to it be converted to: 并且需要将其转换为:
<data>
<release id="9"> <milestone id="36" /> <milestone id="31" /> </release>
<release id="11"> <milestone id="33" /> </release>
</data>
what would the XSLT look like for this transformation? 这种转换的XSLT会是什么样子?
You need to group the items based on their value attribute. 您需要根据项目的value属性对其进行分组。 If you are using xslt 1 you can do this using the Muenchian Method which would look something like:
如果您使用的是xslt 1,则可以使用Muenchian方法执行此操作,该方法类似于:
<xsl:key name="item-value" match="item" use="@value" />
<xsl:template match="/RWFCriteria">
<data>
<xsl:for-each select="item[count(. | key('item-value', @value)[1]) = 1]">
<release id="{@value}">
<xsl:for-each select="key('item-value', @value)">
<milestone id="{@id}" />
</xsl:for-each>
</release>
</xsl:for-each>
</data>
</xsl:template>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.