0

すべての付録要素をラップしたいのですが、最初の付録要素の前の兄弟が一部である場合に限ります。

したがって、入力が次のような場合

<part>
..
..
</part>
<appendix href="..">
</appendix>
<appendix href="..">
</appendix>

その後、出力は次のようになります

<part>
..
..
</part>
<appendices>
  <appendix href="..">
  </appendix>
  <appendix href="..">
  </appendix>
</appendices>

私はXSLTにかなり慣れていません。だから私が今まで試したことはすべて失敗しました。どんな助けでも大歓迎です。

4

1 に答える 1

0

XSLT 2.0 を使用すると、口頭での説明が次のように変換されます。

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

   <xsl:output indent="yes"/>

    <xsl:template match="*[appendix]">
        <xsl:copy>
            <xsl:for-each-group select="*" group-adjacent="boolean(self::appendix)">
                <xsl:choose>
                    <xsl:when test="current-grouping-key() and preceding-sibling::*[1][self::part]">
                        <appendices>
                            <xsl:apply-templates select="current-group()"/>
                        </appendices>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:apply-templates select="current-group()"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:for-each-group>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:transform>
于 2015-07-14T13:27:19.387 に答える