开发者

Accessing XML using XSLT

I have an xml of the following format

<catalog>
 <cd>
  <title>CD name</title>
 </cd>
</catalog>

I can use xslt to get t开发者_JAVA技巧he element value using the following:

<xsl:template match="/">
<xsl:for-each select="catalog/cd">
<xsl:value-of select="title" />
</xsl:for-each>

But, I am trying to figure out the xsl code to read the xml in the following format:

<catalog>
 <cd title="CD name"/>
</catalog>

How do I do this? And if anyone can post some xslt tutorial link, it will be much appreciated.

Thanks in advance


I have an xml of the following format

    <catalog>
     <cd>
      <title>CD name</title>
     </cd>
    </catalog>

I can use xslt to get the element value using the following:

    <xsl:template match="/">
    <xsl:for-each select="catalog/cd">
    <xsl:value-of select="title" />
    </xsl:for-each>

But, I am trying to figure out the xsl code to read the xml in the following format:


    <catalog>
     <cd title="CD name"/>
    </catalog>

How do I do this? And if anyone can post some xslt tutorial link, it will be much appreciated.

This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>

 <xsl:template match="cd">
  <xsl:value-of select="concat(@title, '&#xA;')"/>
 </xsl:template>
</xsl:stylesheet>

when applied on this XML document:

<catalog>
    <cd title="CD1 name"/>
    <cd title="CD2 name"/>
    <cd title="CD3 name"/>
</catalog>

produces the wanted result:

CD1 name
CD2 name
CD3 name

For tutorials and books see my answer to this question:

https://stackoverflow.com/questions/339930/any-good-xslt-tutorial-book-blog-site-online/341589#341589


Another site that is useful for tutorials is: link text

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜