xmlで実行される一般的な変換を含むXSLファイルを作成しました。このファイルは、いくつかの他のXSLファイルに含まれます。これらのファイルは、これらの共通ルールの上にさらに多くのテンプレートを追加します。私が持っている問題は、共通のテンプレートで作成される要素に一致させたいのですが、より具体的なxslがそれに合致する必要があるときに作成されることはありません。 XSL:xsl:新たに作成された要素を別のxslファイルと一致させる
共通stylesheet.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.standards.org/Intake"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"> <!-- xs namespace allows typed functions and parameters -->
<xsl:output method="xml" indent="yes" version="1.0" encoding="UTF-8" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*" />
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:copy-of select="@*" />
<xsl:apply-templates select="@*|node()" />
</xsl:element>
</xsl:template>
<xsl:template match="@*|text()|comment()|processing-instruction()">
<xsl:copy />
</xsl:template>
<!-- remove root -->
<xsl:template match="/*">
<xsl:apply-templates select="node()" />
</xsl:template>
<xsl:template match="OccurrenceData">
<xsl:element name="{local-name()}">
<xsl:element name="custom_Occurrence">
<!-- template adds 2 more elements to custom_Occurrence, omitted for brevity -->
<xsl:call-template name="createOccurrenceContent" />
</xsl:element>
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<!-- rest of stylesheet -->
</xsl:stylesheet>
最初の固有-stylesheet.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:import href="common-stylesheet.xsl" />
<xsl:template match="custom_Occurrence">
<xsl:element name="{local-name()}">
<xsl:element name="custom_TestElement"/>
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<!-- rest of stylesheet -->
</xsl:stylesheet>
私が最初に特定のスタイルシートによって、次の入力XMLを送信しています:
input.xml
<Request>
<RequestData>
<Occurrence>
<OccurrenceCd>EJ104</OccurrenceCd>
<!-- more children -->
</Occurrence>
<!-- rest of input-->
</RequestData>
</Request>
と結果は次のようになります。
分で希望-のOutput.xml
<RequestData>
<Occurrence>
<OccurrenceCd>EJ104</Occurrence>
<custom_Occurrence>
<custom_TestElement />
</custom_Occurrence>
<!--more children -->
</Occurrence>
<!-- rest of output -->
</RequestData>
を予想通り、共通テンプレートが走ったと、彼らは仕事されているが、 <custom_TestElement>
が見つからない場合は、<custom_Occurrence>
にあります。そこには、共通ファイルを特定のxslファイルに含める方法と、特定のファイルが新しい要素に一致する前に共通ファイルテンプレートを実行する方法があります?これは1つのファイルで可能ですか、または変換を独自のステップに分割する必要があります。つまり共通変換を最初に実行してからxmlをより具体的なxmlに変換しますか?
注:私は<xsl:element name="{local-name()}">
を使用しています。ソースxmlには名前空間がないため、特別なテンプレート形式で調整されたIDトランスフォームがあり、共通のxslに1つ適用します。これらがなければ、名前空間はすべての要素に空白値または完全な値のいずれかで適用されました。また、変換にSaxon-HE v9.7.0-8を使用しています。
EDIT:より具体的なスタイルシートにcustom_OCCurrenceの作成を移動できません。その要素ブロックとその内容はすべての特定のスタイルシートで共有され、どちらが使用されているかによって、その要素に「要素」と値が追加されます。
私は分かりません。だから共通の変数を作成し、共通のそれを呼び出すか? – jbailie1991
' ... xsl:element>"の代わりに、私が答えに示したコードを入れて要素が最初に作成されて処理されるようにする必要があります。新しく作成されたノードをテンプレートとマッチさせるという魔法はないので、変数を使用する必要があります。あるいは、実際にはステップを処理する必要があります。 –
これは、私がこのアプローチに正しく従ったと仮定して、custom_Occurrence要素を完全になくしました。コンテキストのコードスニペットを拡張できますか? – jbailie1991