开发者

parsing string as an xml using xslt

开发者 https://www.devze.com 2023-04-07 11:30 出处:网络
I have a requirement, where input is a wel formed xml string. I need to traver开发者_StackOverflow社区se through that string and get some specific value.

I have a requirement, where input is a wel formed xml string. I need to traver开发者_StackOverflow社区se through that string and get some specific value.

input:

<Session>
   <Store>
      <Name>myname</name>
      <ContactId>1234</ContactId>
   </Store>
</Session>

I need to get the value of ContactId and store it in a variable... Please help.


Try this snippet:-

<xsl:template match="/">
    <xsl:value-of select="/Session/Store/ContactId/text()"/>
</xsl:template>


Are you looking something like this:-

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                version="1.0">
    <xsl:variable name="Session">
    <Store>
            <Name>myname</name>
            <ContactId>1234</ContactId>
    </Store>
    </xsl:variable>

    <xsl:template match="/">
       <xsl:value-of select="msxsl:node-set($Session)/Store/ContactId/text()">
    </xsl:template>
</xsl:stylesheet>
0

精彩评论

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

关注公众号