简体   繁体   中英

convert XSLT 2.0 to 1.0

I have the following solution in XSLT 2.0

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/rows">
    <xsl:copy>
        <xsl:for-each-group select="row" group-starting-with="row[item='****************']">
            <xsl:variable name="title-item" select="preceding-sibling::row[1]/item" />
            <xsl:for-each select="current-group()[starts-with(item[1], '#')]">
                <row>
                    <xsl:copy-of select="$title-item, *"/>
                </row>
            </xsl:for-each>
        </xsl:for-each-group>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

as for-each-group is not supported in XSLT 1.0

I want to convert it into XSLT 1.0 version.

Declare eg

<xsl:key name="group" match="row[not(item = '****************')]" use="generate-id(preceding-sibling::row[item='****************'][1])"/>

as a top-level element, then instead of <xsl:for-each-group select="row" group-starting-with="row[item='****************']"> try

<xsl:for-each select="row[item='****************']">
  <xsl:variable name="group" select="key('group', generate-id())"/>
  <xsl:variable name="title-item" select="preceding-sibling::row[1]/item" />
  <xsl:for-each select="$group[starts-with(item[1], '#')]">
                <row>
                    <xsl:copy-of select="$title-item | *"/>
                </row>
   </xsl:for-each>
</xsl:for-each>

But we really need to see some input sample structure plus the wanted result. And I might be overlooking some XSLT/XPath 2 only stuff I have used despite trying to write XSLT 1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM