2017-01-18 7 views
1

XSLをXHTMLに変換して戻すXSL変換を作成しました。 XSLTを初めて使ったのです。今、私は "逆の部分"逆変換を構築していると私は固執しています。概要XSLTパラメータからノードを選択してXMLにマージする

紹介/

だから、ベースXMLは、私が探していますつのノード(frags)が含まれています

<frag id="10" name="Editable_Fragment" > 
<child id="11"></child> 
</frag> 
<frag id="20" name="Editable_Fragment2"> 
<child id="21"></child> 
</frag> 

はところで、このXML内部の断片がたくさんありますが、私は見ているだけ"編集可能な"もののために!だから私はこのようなXSLTを作成しています

<?xml version="1.0"?> 

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
<xsl:output omit-xml-declaration="yes" indent="yes"/> 

<xsl:template match="/"> 

    <xsl:apply-templates select="/review-case/review-document/review-channel/content/region/section/frag[@name='Editable_Fragment']/node()"/> 
    <xsl:apply-templates select="/review-case/review-document/review-channel/content/region/section/frag[@name='Editable_Fragment2']/node()"/> 

</xsl:template> 

<xsl:template match="@*|node()"> 
    <xsl:copy> 
    <xsl:apply-templates select="@*|node()" /> 
    </xsl:copy> 
</xsl:template> 

両方のノードの内容を文字列としてリッチテキストエディタで一緒に保持されています!私は両方のノードのいくつかのデータを変更していて、その後私は、いわゆる逆変換してデータを更新するリッチテキストエディタで

<child id="11" name="Editable_Fragment">....data...</child> 
<child id="21" name="Editable_Fragment">....data...</child> 

:内容は次のようになります。

逆変換の問題が

両方の「子」タグの付いた文字列をパラメータmpTransformParameters以内にさらに処理するために使用されます。私はこのパラメータを使用する必要があります。私は、次のXSLTコードを知っています。私はちょうど、frag id = "10"、child id = "11"、child id = "21"で更新しています。

私の質問は、私は戻って子ID =「11」への「フラグ・ID = 10」と 子IDを更新マージすることができますどのように、ある= "21『フラグ・ID = 20』の両方が文字列の中で一緒にしている場合?

XSLTを "リバース":たくさん

答えて

0

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
<xsl:output indent="yes"/> 
<xsl:param name="mpTransformParameters"/> 

<xsl:template match="review-case/review-document/review-channel/content/region/section/frag/child[@name='Editable_Fragment']"> 
<xsl:value-of select="$mpTransformParameters" disable-output-escaping="yes"/>   
</xsl:template> 

<xsl:template match="@* | node()"> 
<xsl:copy> 
    <xsl:apply-templates select="@* | node()"/> 
</xsl:copy> 
</xsl:template> 

</xsl:stylesheet> 

おかげで、このようなXSLTをお試しください:

それは にあまりにも面倒になるので、私は意図的に、 XSLT 2.0を選択
<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output indent="yes" omit-xml-declaration="yes"/> 
    <xsl:param name="mpTransformParameters"> 
    &lt;child id="11" name="Editable_Fragment"&gt;..data 11..&lt;/child&gt; 
    &lt;child id="21" name="Editable_Fragment"&gt;..data 22..&lt;/child&gt; 
    </xsl:param> 

    <xsl:template match="section"> 
    <xsl:variable name="tbl" 
     select="tokenize($mpTransformParameters, '&lt;/child&gt;')"/> 
    <xsl:copy> 
     <xsl:for-each select="$tbl"> 
     <xsl:analyze-string select="." 
      regex="id=&quot;(\d+)&quot;.*&gt;(.*)"> 
      <xsl:matching-substring> 
      <xsl:variable name="id" select="number(regex-group(1)) - 1"/> 
      <xsl:variable name="txt" select="regex-group(2)"/> 
      <xsl:variable name="nm"> 
       <xsl:if test="$id=10"><xsl:text>Editable_Fragment</xsl:text></xsl:if> 
       <xsl:if test="$id=20"><xsl:text>Editable_Fragment2</xsl:text></xsl:if> 
      </xsl:variable> 
      <xsl:element name="frag"> 
       <xsl:attribute name="id" select="$id"/> 
       <xsl:attribute name="name" select="$nm"/> 
       <xsl:value-of select="$txt"/> 
      </xsl:element> 
      </xsl:matching-substring> 
     </xsl:analyze-string> 
     </xsl:for-each> 
    </xsl:copy> 
    </xsl:template> 

    <xsl:template match="@* | node()"> 
    <xsl:copy><xsl:apply-templates select="@* | node()"/></xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 

は、バージョン1.0 でそれを書きます。

テスト実行の目的で、mpTransformParameterにサンプル値を割り当てました。

あなたが書いたように、私は実際のコンテンツがmpTransformParametersであることを、セクション要素のダミー内容と少し単純化されたXML入力を準備:

それを使用して ​​

、私は以下の結果を得ました

<region> 
    <section> 
     <frag id="10" name="Editable_Fragment">..data 11..</frag> 
     <frag id="20" name="Editable_Fragment2">..data 22..</frag> 
    </section> 
</region> 
関連する問題