2つのXSLファイルの機能を単一のファイルにマージします(以前のQの継続…)
-
10-10-2019 - |
質問
これは私の以前の質問の継続です(同様のタイプの質問を再び再投稿して申し訳ありません):
2つのXSLファイルの機能を単一のファイルにマージします(XSLのインポートではなく、問題を含む)
と
2つのXSLファイルの機能を単一のファイルにマージします(続き.....)
これは実際、私の2番目の質問の少し操作です。ここで、提供されるソリューションをマージする必要があります フラック 私の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>
次のようなサンプル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>
出力する必要があります:
<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>
事前に助けてくれてありがとう。
解決
このスタイルシート:
<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>
ノート: :IDルールを上書きするルール。
所属していません StackOverflow