使用xslt将字符串解析为xml

时间:2011-09-26 17:16:53

标签: xslt-1.0

我有一个要求,其中输入是一个形成的xml字符串。我需要遍历该字符串并获得一些特定的值。

输入:

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

我需要获取ContactId的值并将其存储在变量中... 请帮忙。

2 个答案:

答案 0 :(得分:0)

试试这个片段: -

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

答案 1 :(得分:0)

你看起来像这样: -

<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>