开发者

fetching data from xml using xslt

开发者 https://www.devze.com 2023-03-06 08:03 出处:网络
having a xml with same tag names but for that tag names values were different , so we expecting an output like one by one transaction

having a xml with same tag names but for that tag names values were different , so we expecting an output like one by one transaction

<swift>
 <message>
 <block3>
    <tag>
       <name>32</name>
       <value>praveen</value>
    </tag>
    <tag>
       <name>42</name>
       <value>pubby</value>
   </tag>
</block3> 
<block4>
    <tag>
       <name>77</name>
       <value>pravz</value>
    </tag>
    <tag>
        <name>77</name>
        <value>pubbypravz</value>
    </tag>
    <tag>
        <name>76</name>
         <value>shanmu</value>
   </tag>
   </block4>
  </message>
</swift>

xslt

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">            
    <xsl:for-each select="swift/开发者_如何学Cmessage">   

                  <xsl:for-each select ="block3/tag[name = '32']">
            <xsl:value-of select="value"/>
        </xsl:for-each>,<xsl:text/>

                    <xsl:for-each select ="block4/tag[name = '77']">
            <xsl:value-of select="value"/>,<xsl:text/>
        </xsl:for-each>

        </xsl:for-each>

</xsl:template>

by this above xslt i have reached up to this

praveen,pravz,pubbypravz,

output needed:

 praveen,pravz

 praveen,pubbypravz

hope we need to set a loop for each time please guide me ...


Well, you changed your first example completely, so my first answer did not match any more to your question. That makes our discussion some kind of worthless for outsiders. Nevertheless, I adapted my solution to your new input data:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" />

    <xsl:template match="/">
    <xsl:for-each select ="/swift/message/block3/tag[name='32']">
       <xsl:variable name = "first-val" select="value"/>
       <xsl:for-each select ="/swift/message/block4/tag[name='77']">
           <xsl:value-of select="concat($first-val, ',',value)"/>
<xsl:text>
</xsl:text>
       </xsl:for-each>
    </xsl:for-each>

    </xsl:template>
</xsl:stylesheet>

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消