2017-06-23 11 views
0

は、私は、ファイル名の.BAKを削除することによって、このXMLを変換するためにXSLを使用したい、これが私のxml利用XSLのxmlタグ内のプロパティ値を変更する

<?xml version="1.0" encoding="UTF-8"?> 
<node> 
    <file name="abc.txt.bak"> 
     <fileid value="112358"/> 
    </file> 
    <location value="Baker Street"/> 
</node> 

であると言います。 期待される結果は、このようなものです:

<?xml version="1.0" encoding="UTF-8"?> 
<node> 
    <file name="abc.txt"> 
     <fileid value="112358"/> 
    </file> 
    <location value="Baker Street"/> 
</node> 

私のXSLファイルは動作しません。これは、このようなものです。値を変更せずにすべてをコピーするだけです。

<?xml version="1.0" encoding="UTF-8" standalone="no" ?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output method="xml" indent="yes"/> 
    <xsl:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="node/file/@name" > 
     <xsl:copy> 
      <xsl:attribute name="name"> 
       <xsl:value-of select="substring-before(., '.bak')" /> 
      </xsl:attribute> 
     </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 
+0

の可能性のある重複した[XSLT:?時の属性値を変更する方法](https://stackoverflow.com/questions/615875/xslt-how-to-change-an-attribute-value-during -xslcopy) – dave

+0

''の周りの ''ラッパーを削除するだけです。 –

+0

いいえ、それは動作しません – siriuswangch

答えて

0

私自身の質問を解決しました。ちょうど共有する。

<?xml version="1.0" encoding="UTF-8" standalone="no" ?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output method="xml" indent="yes"/> 
    <xsl:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="node/file"> 

     <xsl:variable name="bak_file_name"> 
      <xsl:value-of select="@name" /> 
     </xsl:variable> 

     <xsl:copy> 
      <xsl:apply-templates select="@*"/> 
       <xsl:attribute name="name"> 
          <xsl:value-of select="substring-before($bak_file_name, '.bak')" /> 
       </xsl:attribute> 
      <xsl:apply-templates select="fileid"/> 
     </xsl:copy> 


    </xsl:template> 



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