2017-12-28 32 views
0

すべての要素名を小文字にし、idフィールド以外のすべてに接頭辞を追加するXSLTを取得しようとしています。 idフィールドがコピーされないことを除いて、すべて動作します。そのままコピーする必要のある要素名の前に接頭辞

は、ここに私の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:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" /> 
    <xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'" /> 

    <xsl:template match="*"> 
     <xsl:element name="theprefix_{translate(local-name(), $uppercase, $lowercase)}" namespace="{namespace-uri()}"> 
      <xsl:apply-templates select="@*|node()[not(self::unique_id)]"/> 
     </xsl:element> 
    </xsl:template> 


    <xsl:template match="@*"> 
     <xsl:attribute name="{translate(local-name(), $uppercase, $lowercase)}" namespace="{namespace-uri()}"> 
      <xsl:value-of select="."/> 
     </xsl:attribute> 
    </xsl:template> 

    <xsl:template match="comment() | text() | processing-instruction()"> 
     <xsl:copy/> 
    </xsl:template> 

    </xsl:stylesheet> 

答えて

0

あなたのXSLTサンプルでunique_idを使用しているので、私はあなたがどんな変更(ないid)せずに、単にこの要素を維持したい 、想定しています。

unique_idテンプレートマッチングを追加:

<xsl:template match="unique_id"> 
    <xsl:copy-of select="."/> 
</xsl:template> 

します。コードから[not(self::unique_id)]を削除します。 unique_idその「勝利」の 場合にだけ、それは任意unique_idノードを処理するよう

追加テンプレートは、テンプレートマッチング「*」よりも特異的です。

+0

ありがとうございます、チャンピオンのように動作します。私はテンプレートマッチングがどのように働くかを読む必要があります。私は彼らがそんなことをしてしまったのか分からなかった。 – JvmSd121

関連する問題