parsing string as an xml using xslt
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>
精彩评论