迭代未知的xml节点

时间:2017-11-02 17:18:07

标签: xml xslt xpath

假设我有类似下面的XML,但就我而言,我不知道XML的结构:

<catalog>
  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Hide your heart</title>
    <artist>Bonnie Tyler</artist>
    <country>UK</country>
    <company>CBS Records</company>
    <price>9.90</price>
    <year>1988</year>
  </cd>
  <cd>
    <title>Greatest Hits</title>
    <artist>Dolly Parton</artist>
    <country>USA</country>
    <company>RCA</company>
    <price>9.90</price>
    <year>1982</year>
  </cd>
</catalog>

想要在节点上迭代并打印该节点的东西:

<xsl:template match="/*[count(descendant::*) > 0]">
    <xsl:for-each select="parent">
        <xsl:call-template name="generateClass">
            <xsl:with-param name="className" select="name(.)"/>
        </xsl:call-template>
    </xsl:for-each>
</xsl:template>

0 个答案:

没有答案