2016-09-09 2 views
0

子タグ名をxslに置き換える方法。 ここではxmlの私の構造です。xml要素を、javaを使用してxslスタイルシートの助けを借りて置き換えた場合、置き換えられません。

<Checkpax xmlns="http://xml.api.com/test"> 
    <customerLevel> 
     <customerDetails> 
      <paxDetails> 
       <surname>MUKHERJEE</surname> 
       <type>A</type> 
       <gender>M</gender> 
      </paxDetails> 
      <otherPaxDetails> 
       <givenName>JOY</givenName> 
       <title>MR</title> 
       <age>11</age> 
      </otherPaxDetails> 
      <otherPaxDetails> 
       <title>MR</title> 
      </otherPaxDetails> 
     </customerDetails> 
     <staffDetails> 
      <staffInfo/> 
      <staffCategoryInfo> 
       <attributeDetails> 
        <attributeType>NA</attributeType> 
       </attributeDetails> 
      </staffCategoryInfo> 
     </staffDetails> 
     <productLevel> 
      <legLevel> 
       <legLevelIndicator> 
        <statusDetails> 
         <indicator>abc</indicator> 
         <action>1</action> 
        </statusDetails> 
       </legLevelIndicator> 
      </legLevel> 
     </productLevel> 
     <CustomerLevel> 
      <legLevel> 
       <legLevelIndicator> 
        <statusDetails> 
         <indicator>cde</indicator> 
         <action>1</action> 
        </statusDetails> 
       </legLevelIndicator> 
      </legLevel> 
     </CustomerLevel> 
    </customerLevel> 
</Checkpax> 

以下の私のXSLファイル

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" omit-xml-declaration="yes"/> 
    <xsl:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()" /> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="customerLevel/productLevel/legLevel/legLevelIndicator/statusDetails"> 
     <statusInformation> 
      <xsl:apply-templates select="@*|node()" /> 
     </statusInformation> 
    </xsl:template> 
</xsl:stylesheet> 
ここ

statusDetails名はProductLevel/LeglevelIndicator内部staffInformationように変更する必要があります。親切に私にこれを行うための提案をください。

以下と予想される結果

<Checkpax xmlns="http://xml.api.com/test"> 
     <customerLevel> 
      <customerDetails> 
       <paxDetails> 
        <surname>MUKHERJEE</surname> 
        <type>A</type> 
        <gender>M</gender> 
       </paxDetails> 
       <otherPaxDetails> 
        <givenName>JOY</givenName> 
        <title>MR</title> 
        <age>11</age> 
       </otherPaxDetails> 
       <otherPaxDetails> 
        <title>MR</title> 
       </otherPaxDetails> 
      </customerDetails> 
      <staffDetails> 
       <staffInfo/> 
       <staffCategoryInfo> 
        <attributeDetails> 
         <attributeType>NA</attributeType> 
        </attributeDetails> 
       </staffCategoryInfo> 
      </staffDetails> 
      <productLevel> 
       <legLevel> 
        <legLevelIndicator> 
         <statusInformation> 
          <indicator>abc</indicator> 
          <action>1</action> 
         </statusInformation> 
        </legLevelIndicator> 
       </legLevel> 
      </productLevel> 
      <CustomerLevel> 
       <legLevel> 
        <legLevelIndicator> 
         <statusDetails> 
          <indicator>cde</indicator> 
          <action>1</action> 
         </statusDetails> 
        </legLevelIndicator> 
       </legLevel> 
      </CustomerLevel> 
     </customerLevel> 
    </Checkpax> 
+0

**正確な結果を投稿してください。 –

+0

質問が更新されました。 – sathya

答えて

1

statusDetails名が 内staffInformationように変更する必要がありますProductLevel/LeglevelIndicator

このようにそれを試してみてください。

XSLT 1.0

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

<!-- identity transform --> 
<xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="ns0:productLevel/ns0:legLevel/ns0:legLevelIndicator/ns0:statusDetails"> 
    <staffInformation xmlns="http://xml.api.com/test"> 
     <xsl:apply-templates/> 
    </staffInformation> 
</xsl:template> 

</xsl:stylesheet> 
関連する問題