How to parse XML using XSLT?

回眸只為那壹抹淺笑 提交于 2019-12-11 08:27:57

问题


I have an XML with data as follows

<Item1>
  <item2>
    <Item3>111</Item3>
  <Item2>
</Item11>

To get the value 111 in Item3

<xsl:choose>
  <xsl:value-of select="Item1/Item2/Item3"/>
</xsl:choose>

In XSLT . Now I need to get the following:

<Product1>
  <Product2>
    <Product3 ValidYN="Y" ProducType="ABC">333</Product3>
    <Product3 ValidYN="Y" ProducType="DEF">444</Product3>
    <Product3 ValidYN="Y" ProducType="GHI">555</Product3>
  <Product12>
</Product1>

I need to take values 333 , 444 , 555 based on ProducType.How to do the same using XSLT


回答1:


To select a node based on values in relation to it, you can use XPaths like this:

/Product1/Product2/Product3[@ValidYN = 'Y' and @ProductType = 'ABC']
/Product1/Product2/Product3[@ValidYN = 'Y' and @ProductType = 'DEF']
/Product1/Product2/Product3[@ValidYN = 'Y' and @ProductType = 'GHI']

the parts in [square brackets] are called "predicates."



来源:https://stackoverflow.com/questions/15549061/how-to-parse-xml-using-xslt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!