Extracting node values using XSLT

2019-09-21 09:59发布

I have an xml like below

<Envelope>
<Body>
<response>
<timestamp>
<status>
<Objectstatus>
<class>stats</class>
<Adminstate>disabled</Adminstate>
<name>abc</name>
</objectstatus>
<objectstatus>
<class>Policy</class>
<adminstate>enabled</adminstate>
<names>xyz</name>
</Objectstatus>

The response expected is stats,disabled,abc Policy,enabled,xyz

Could you please tell me how i can do it using a stylesheet.

标签: xslt
1条回答
来,给爷笑一个
2楼-- · 2019-09-21 10:22

First thing first, make sure your child nodes have all the same name (Adminstate or adminstate, etc...), remember that it is case sensitive.

I'm also assuming you would like a HTML output, here's what you could try:

 <xsl:for-each select="//Objectstatus">
   <p>
     <xsl:value-of select="./class"/>
     <xsl:text>,</xsl:text>
     <xsl:value-of select="./Adminstate"/>
     <xsl:text>,</xsl:text>
     <xsl:value-of select="./name"/>
   </p>
 </xsl:for-each>

Here's the output:

stats,disabled,abc Policy,enabled,xyz

查看更多
登录 后发表回答