2012-08-01 54 views
-1

編寫製作XML文檔副本的XSLT樣式表。源文檔具有大寫的元素和屬性名稱。輸出文檔應該是精確副本,但元素和屬性名稱是小寫的。例如,它應該轉換:製作XML文檔副本的XSLT樣式表

<p> 
<BODY ATTRIBUTE="TheValue"> 
<H1>Hello world</H1> 
</BODY> 

into 

<body attribute=」TheValue」> 
<h1>Hello world</h1> 
</body> 

回答

2

試試這個:

<?xml version="1.0"?> 
<!-- Transform a document to itself, lowercasing all tag names --> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <!-- Import the identity transformation --> 
    <!-- Whenever you match any node or any attribute --> 
    <xsl:template match="node()|@*"> 
     <!-- Copy the current node --> 
     <xsl:copy> 
      <!-- Including any attributes it has and any child nodes --> 
      <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
    </xsl:template> 
    <!-- Whenever you match any node or any attribute --> 
    <!-- When you match any element --> 
    <xsl:template match="*"> 
     <!-- Create the same element with a lowercase name --> 
     <xsl:element name="{translate(name(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')}"> 
      <!-- Including any attributes it has and any child nodes --> 
      <xsl:apply-templates select="@*|node()"/> 
     </xsl:element> 
    </xsl:template> 
</xsl:stylesheet> 
+0

不工作。屬性名稱不是小寫。 – mzjn 2012-08-01 17:33:26

+0

因爲我沒有做屬性。你需要調整它。答案就在你面前。 – Vinit 2012-08-01 17:39:09

+0

因爲它的功課.. – Vinit 2012-08-01 17:46:19