0

入力:

    <book>
     <chapter href="..">
      <topicref chunk="to-content" href"..">

      </topicref>
      <topicref chunk="to-content" href"..">

      </topicref>
     </chapter>
    </book>    

出力:

    <book>
     <chapter chunk="to-content" href="..">
      <topicref href"..">

      </topicref>
      <topicref href"..">

      </topicref>
     </chapter>
    </book> 

xsl:attribute name="chunk">to-content</xsl:attribute>「前の手順で子を作成すると、ここに属性を作成すると失敗します」とスローされるため、使用できません。警告とその後のエラー。ここに記載されていることを理解しています。回避策はありますか?

XSLT 2.0 を Saxon 9 で使用しています (まだ XSLT/ SO のコツをつかんでいます)。これが広すぎる場合は申し訳ありませんが、あらゆる方向の助けをいただければ幸いです。

4

2 に答える 2

0

これを試して:

<xsl:template match="/">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="chapter">
  <xsl:copy>
    <!-- If the chapter contains a topicref with chunk="to-content", set chunk to-content on the chapter unless it's already there.-->
    <xsl:if test=".//topicref/@chunk = 'to-content' and not(@chunk='to-content')">
      <xsl:attribute name="chunk">to-content</xsl:attribute>
    </xsl:if>
    <!-- Copy all chapter attributes -->
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<xsl:template match="topicref">
  <xsl:copy>
    <!-- Copy every attribute except chunk="to-content" -->
    <xsl:copy-of select="@*[not(name() = 'chunk' and . = 'to-content')]"/>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<xsl:template match="*">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>
于 2015-08-01T21:02:04.800 に答える