Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt 将两个xsl文件的功能合并到一个文件中(继续我以前的Q';s…)_Xslt_Xslt 1.0_Xslcompiledtransform - Fatal编程技术网

Xslt 将两个xsl文件的功能合并到一个文件中(继续我以前的Q';s…)

Xslt 将两个xsl文件的功能合并到一个文件中(继续我以前的Q';s…),xslt,xslt-1.0,xslcompiledtransform,Xslt,Xslt 1.0,Xslcompiledtransform,这是我之前问题的延续(很抱歉再次发布类似类型的问题): 及 这实际上是对我的第二个问题的一点操纵。 我现在需要将Flack提供的解决方案与xsl中的“选择”条件合并到我的第一个问题: <xsl:choose> <xsl:when test='/Declaration/Header/DeclarantsReference = ""'> <DeclarantsReference> <

这是我之前问题的延续(很抱歉再次发布类似类型的问题):

这实际上是对我的第二个问题的一点操纵。 我现在需要将Flack提供的解决方案与xsl中的“选择”条件合并到我的第一个问题:

<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>

A.
现在,任何示例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>

#+#
5.
ISD
XXX
#+#
应输出:

<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>

5.
ISD
A.
XXX
提前感谢您的帮助。

此样式表:

<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>

A.
输出:

<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>

5.
ISD
A.
XXX

注意:规则覆盖标识规则。

因为您没有选择正确的解决方案(管道),您现在(将来也会经常)遇到新问题。您的代码将越来越多地具有意大利面的外观,可维护性将不断恶化。现在回到先前提供给您的流水线解决方案并不是很晚。让这成为一个很好的教训。@Dimitre:管道不是正确的解决方案。这里我们有一些规则覆盖了身份规则。@Alejandro:那么这个OP就无法用可以理解的方式解释他的问题了。他显然使用了错误的编码风格,但他没有提供完整的示例,因此我们无法通过提供更好的编码风格的解决方案来帮助他。。。