2013-10-18 67 views
1

我發現了很多關於通過XSLT函數translate(source,sourceChars,outputChars)翻譯特定元素/屬性以便翻譯(「čašaž」,「čšž」,「csz」)= casaz通過XSLT刪除整個XML文檔中的變音符號

我需要XSLT模板,它翻譯每個節點和每個屬性。 我不知道源XML的結構,所以它必須是通用的,不依賴於屬性或元素名稱和值。

我尋找的是這樣的僞轉型:

<xsl:template match="@*"> 
    <xsl:copy> 
     <xsl:apply-templates select="translate(. , "čžš","czs")"/> 
    </xsl:copy> 
    </xsl:template> 

    <xsl:template match="node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="translate(. , "čžš","czs")"/> 
    </xsl:copy> 
    </xsl:template> 

回答

2

你可以寫一個包含數據要正常化,下面我做這些元素的模板,屬性值,文本節點,註釋節點和處理指令數據。

<xsl:param name="in" select="'čžš'"/> 
<xsl:param name="out" select="'czs'"/> 

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

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

<xsl:template match="text()"> 
    <xsl:value-of select="translate(., $in, $out)"/> 
</xsl:template> 

<xsl:template match="comment()"> 
    <xsl:comment> 
    <xsl:value-of select="translate(., $in, $out)"/> 
    </xsl:comment> 
</xsl:template> 

<xsl:template match="processing-instruction()"> 
    <xsl:processing-instruction name="{name()}"> 
    <xsl:value-of select="translate(., $in, $out)"/> 
    </xsl:processing-instruction> 
</xsl:template>