2011-01-12 6 views
0

これは私の以前の質問の続きに(再び質問の再投稿似たタイプのため申し訳ありません)です:マージ機能(私の以前のQさんの継続が.....)

Merge functionality of two xsl files into a single file (not a xsl import or include issue)

Merge functionality of two xsl files into a single file (continued.....)

これは実際に私の2番目の質問のビット操作です。

<xsl:choose> 
      <xsl:when test='/Declaration/Header/DeclarantsReference = ""'> 
      <DeclarantsReference> 
       <xsl:text disable-output-escaping="no">A</xsl:text> 
      </DeclarantsReference> 
      </xsl:when> 
      <xsl:otherwise> 
      <DeclarantsReference> 
       <xsl:value-of select="/Declaration/Header/DeclarantsReference"/> 
      </DeclarantsReference> 
      </xsl:otherwise> 
     </xsl:choose> 

今すぐ任意のサンプルXML入力のように:

<Declaration> 
     <Message> 
      <Meduim>#+#</Meduim> 
      <CommonAccessReference></CommonAccessReference> 
     </Message> 
     <BeginingOfMessage> 
      <MessageCode>5</MessageCode> 
      <DeclarationCurrency></DeclarationCurrency> 
      <MessageFunction>ISD</MessageFunction> 
     </BeginingOfMessage> 
     <Header> 
      <DeclarantsReference></DeclarantsReference> 
      <Items> 
      <Documents> 
        <ItemDocument> 
        <DocumentCode>XXX</DocumentCode> 
        <DocumentPart></DocumentPart> 
        <DocumentLanguage>#+#</DocumentLanguage> 
        </ItemDocument> 
       </Documents> 
      </Items> 
      </Header> 
</Declaration> 

出力すべき 私は今、私のXSLに「選択」状態で私の最初の質問にフラックが提供するソリューションをマージする必要があります:

<Declaration> 
<Message> 
    <Meduim></Meduim> 
</Message> 
<BeginingOfMessage> 
    <MessageCode>5</MessageCode> 
    <MessageFunction>ISD</MessageFunction> 
</BeginingOfMessage> 
<Header> 
<DeclarantsReference>A</DeclarantsReference> 
    <Items> 
    <Documents> 
    <ItemDocument> 
    <DocumentCode>XXX</DocumentCode> 
    <DocumentLanguage></DocumentLanguage> 
    </ItemDocument> 
    </Documents> 
    </Items> 
</Header> 
</Declaration> 

ご協力いただきありがとうございます。

+0

正しい解決策(パイプライン化)を選択しなかったため、新しい問題が発生しています(今後も継続される予定です)。あなたのコードはますますスパゲッティのような外観を持ち、保守性は絶えず低下します。遅れて戻って、以前に与えられたパイプラインソリューションに戻すのは遅くはありません。これは良いレッスンにしましょう。 –

+0

@ Dimitre:パイプラインは適切なソリューションではありませんでした。ここでは、アイデンティティルールを上書きするいくつかのルールがあります。 –

+1

@Alejandro:このOPは、理解できる方法で彼の問題を説明することができないことに苦しんでいます。彼は明らかに間違ったコーディングスタイルを使用していますが、彼は完全な例を提供していないので、より良いコーディングスタイルのソリューションを提供することによって助けてはなりません... –

答えて

0

このスタイルシート:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="@* | node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@* | node()"/> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="*[not(node())]"/> 
    <xsl:template match="text()" name="strip"> 
     <xsl:param name="pString" select="."/> 
     <xsl:param name="pOutput" select="substring-before($pString,'#+#')"/> 
     <xsl:choose> 
      <xsl:when test="contains($pString,'#+#')"> 
       <xsl:call-template name="strip"> 
        <xsl:with-param name="pString" 
            select="substring-after($pString,'#+#')"/> 
        <xsl:with-param name="pOutput" 
            select="concat($pOutput, 
                substring-before($pString, 
                    '#+#'))"/> 
       </xsl:call-template> 
      </xsl:when> 
      <xsl:otherwise> 
       <xsl:value-of select="concat($pOutput,$pString)"/> 
      </xsl:otherwise> 
     </xsl:choose> 
    </xsl:template> 
    <xsl:template match="DeclarantsReference[not(node())]" 
        priority="1"> 
     <xsl:copy>A</xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 

出力:

<Declaration> 
    <Message> 
     <Meduim></Meduim> 
    </Message> 
    <BeginingOfMessage> 
     <MessageCode>5</MessageCode> 
     <MessageFunction>ISD</MessageFunction> 
    </BeginingOfMessage> 
    <Header> 
     <DeclarantsReference>A</DeclarantsReference> 
     <Items> 
      <Documents> 
       <ItemDocument> 
        <DocumentCode>XXX</DocumentCode> 
        <DocumentLanguage></DocumentLanguage> 
       </ItemDocument> 
      </Documents> 
     </Items> 
    </Header> 
</Declaration> 

:アイデンティティのルールを上書きするルール。

関連する問題