xslt循环转换子元素

转换源xml

    <keywords class="array">
        <e type="string">e1</e>
        <e type="string">e2</e>
    </keywords>

转换规则

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" cdata-section-elements="title artist"/>
<!-- match the document root -->
<xsl:template match="/">
<tt>
<xsl:value-of select="o/keywords/e"/>
</tt>
<package>
    <xsl:for-each select="o/keywords/e">
      <title><xsl:value-of select="child::text()"/></title>
      <artist><xsl:value-of select="child::text()"/></artist>
    </xsl:for-each>
</package>
</xsl:template>
</xsl:stylesheet>

转化结果

<?xml version="1.0" encoding="UTF-8"?>
<tt>e1</tt>
<package>
<title><![CDATA[e1]]></title>
<artist><![CDATA[e2]]></artist>
<title><![CDATA[e1]]></title>
<artist><![CDATA[e2]]></artist>
</package>

参考信息

http://www.ics.uci.edu/~alspaugh/cls/shr/xslt.html

原文地址:https://www.cnblogs.com/zhao1949/p/6738517.html