2016-08-26 4 views
2

基本的に私は現在3つの異なるXMLのために働く3つの別々のXSLTを持っています。その代わりに、特定のXSLTを実行し、結果として整形式のXMLを取得するために、特定の受信者の基盤を決定できる単一のXSLTが必要です。XSLT内で別のXSLTを実行するにはどうすればよいですか?

私は、次の方法使用してみました -

<?xml version="1.0" encoding="UTF-8"?> 
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  
       <xsl:choose> 
        <xsl:when test="fruits/apples"> 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
         <xsl:template match="/"> 
         <data> 
         <doc api_type="2" key="20" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:custom="urn:custom.com" "> 
          <custom:DataSet xyt1:type="tdc:somedataset"> 
           <custom:some_table> 
           <custom:anothertable> 
            <xyt1:key> 
             <xyt1:fruitqty> 
          <xsl:value-of select="fruit/apple"/> 
             </xyt1:fruitqty> 
            </xyt1:key> 
            <end of this xslt> 
      </xsl:when> 
      <xsl:when test="vegetables/tomatoes"> 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
         <xsl:template match="/"> 
         <data> 
         <doc api_type="3" key="100" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:custom="urn:custom.com" "> 
          <custom:DataSet xyt1:type="tdc:somedataset2"> 
           <custom:some_table2> 
           <custom:anothertable2> 
            <xyt1:fruitqty> 
          <xsl:value-of select="fruit/oranges"/> 
             </xyt1:fruitqty> 
            <end of this xslt2> 
     </xsl:when> 
     </xsl:choose> 
     </xsl:template> 
     </xsl:stylesheet> 

を、私はこのような二つの異なるXMLファイルを取得します -

ファイル1 -

<fruits> 
     <apple>2</apple>   
    </fruits> 

ファイル2 -

<vegetables> 
    <tomatoes>2</tomatoes>   
</vegetables> 

だからフルーツ/リンゴが見つかったら最初のxsltを実行し、野菜/トマトはもう一方を実行したい。

正確に入力XMLノードに基づいて、個々の作業ファイルがある特定のXSLTを実行したいが、すべてを1つのXSLTに入れたい。

このメソッドは正しいブロック内にありますが、「ノード」のいずれも出力していません。単にXML内の値を出力しています。例えばのために

.- それはちょうど私が正しくフォーマットされたXMLを取得することはできません結果としてリンゴやない<xyt1:fruitqty> 2 </xyt1:fruitqty>.

のようなノードに対して「2」を示しています。どのようにこの権利を取得するための任意のアイデア?

+0

を確認してください:[MCVE]答えのための –

答えて

0

果物/リンゴが見つかったときに最初のxsltを実行し、野菜/トマトについて を実行します。

私はたとえば、あなたが入力の各タイプに一致するように、個々のテンプレートを使用することをお勧め:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<xsl:template match="/"> 
    <output> 
     <!-- instructions common to all types --> 
     <xsl:apply-templates/> 
    </output> 
</xsl:template> 

<xsl:template match="/fruits"> 
    <!-- instructions for transforming fruits --> 
</xsl:template> 

<xsl:template match="/vegetables"> 
    <!-- instructions for transforming vegetables --> 
</xsl:template> 

</xsl:stylesheet> 
+0

感謝を。私は質問の詳細を変更しました。それを見直していただけますか?私はif elseが受け取ったXMLに基づいていて、適切なXSLTを実行したい。 – sandunes90

+0

新しい例に合わせて自分の答えを編集しました。私は**この**のために "もし他の場合"を使用することをお勧めしません**。 –

関連する問題