2016-04-25 6 views
1

すべて、新しい要素内の各ヘルプのXSLT

これはあなたにとって非常に簡単ですが、初心者として私は正しいことができません。 :(

正しいXLSTどうあるべきか、予想される出力については、以下を事前に感謝を参照して入力してくださいXML:。?。

<map> 
 
    <title>Lang's Commercial Leasing in Australia</title> 
 
    <topic id="io1529956sl235024462" /> 
 
    <topichead navtitle="PRECEDENT FINDING LISTS" id="io2559290sl622242477"> 
 
\t \t <topic id="io2558936sl197225260" /> 
 
\t \t <topic id="io2558936sl197225261" /> 
 
\t \t <topic id="io2558936sl197225262" /> 
 
    </topichead> 
 
</map>

XLST

<?xml version="1.0" encoding="UTF-8"?> 
 
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
 
    \t <xsl:output method="xml" indent="yes" /> 
 
    \t <xsl:strip-space elements="*"/> 
 
    \t <xsl:template match="/"> 
 
    \t \t <xsl:apply-templates select="@*|node()" /> 
 
    \t </xsl:template> 
 
    \t <xsl:template match="@*|node()"> 
 
    \t \t <xsl:copy> 
 
    \t \t \t <xsl:apply-templates select="@*|node()" /> 
 
    \t \t </xsl:copy> 
 
    \t </xsl:template> 
 
    \t <xsl:template match="map/topichead/topic"> 
 
      <comm.intro> 
 
    \t \t \t <group> 
 
    \t \t \t <xsl:attribute name="link"><xsl:value-of select="@id" /></xsl:attribute> 
 
    \t \t \t <xsl:apply-templates select="node()" /> 
 
    \t \t \t </group> 
 
      </comm.intro> 
 
    \t </xsl:template> 
 
    </xsl:stylesheet>

出力:

<map> 
 
    <title>Lang's Commercial Leasing in Australia</title> 
 
    <topic id="io1529956sl235024462" /> 
 
    <topichead navtitle="PRECEDENT FINDING LISTS" id="io2559290sl622242477"> 
 
    <comm.intro> 
 
\t \t <group link="io2558936sl197225260"> 
 
    </comm.intro> 
 
    <comm.intro> 
 
\t \t <group link="io2558936sl197225261"> 
 
    </comm.intro> 
 
    <comm.intro> 
 
\t \t <group link="io2558936sl197225262"> 
 
    </comm.intro> 
 
    </topichead> 
 
</map>

予想される出力:

<map> 
 
    <title>Lang's Commercial Leasing in Australia</title> 
 
    <topic id="io1529956sl235024462" /> 
 
    <topichead navtitle="PRECEDENT FINDING LISTS" id="io2559290sl622242477"> 
 
    <comm.intro> 
 
\t \t <group link="io2558936sl197225260"> 
 
\t \t <group link="io2558936sl197225261"> 
 
\t \t <group link="io2558936sl197225262"> 
 
    </comm.intro> 
 
    </topichead> 
 
</map>

答えて

0

代わりの

<xsl:template match="map/topichead/topic"> 
     <comm.intro> 
      <group> 
      <xsl:attribute name="link"><xsl:value-of select="@id" /></xsl:attribute> 
      <xsl:apply-templates select="node()" /> 
      </group> 
     </comm.intro> 
    </xsl:template> 

使用の2つのテンプレート

<xsl:template match="map/topichead"> 
     <xsl:copy> 
     <xsl:apply-templates select="@*"/> 
     <comm.intro> 
      <xsl:apply-templates/> 
     </comm.intro> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="map/topichead/topic"> 
     <group link="{@id}"> 
      <xsl:apply-templates/> 
     </group> 
    </xsl:template> 

そして、あなたは、あなたが持っている最初のテンプレート<xsl:template match="/">を必要としない、文書ノードの子は、組み込みテンプレートによって処理されています。

+0

ありがとうございます。私は本当にあなたの助けに感謝します。 –

関連する問題