要在XSLT做到這一切你需要的是一個基本恆等變換,與該<storybody>
元素異常。
事情是這樣的:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="storybody">
<body>
<xsl:apply-templates select="@*|node()"/>
</body>
</xsl:template>
</xsl:stylesheet>
編輯
我看了你的評論,「我不希望使用恆等變換而我需要使用身份轉換。在文檔「中的一個元素上,並且我不清楚你需要什麼。也許你對文檔的其餘部分有改變,但是對這個元素有困難?在這種情況下,除了你已經寫過的內容外,你應該只使用我答案中的第二個模板。
你的消息的第二部分是部分失去了標記,但現在已經被固定,我忽略了它。要將<URI>
元素更改爲<a>
以及您應該添加另一個模板。假設你想在原來的ref
屬性更改爲href
,兩人在一起看起來像這樣
<xsl:template match="storybody">
<body>
<xsl:apply-templates select="@*|node()"/>
</body>
</xsl:template>
<xsl:template match="storybody//URI">
<a>
<xsl:attribute name="href">
<xsl:value-of select="@ref" />
</xsl:attribute>
</a>
</xsl:template>
如果你的目的是什麼與此不同,請澄清,我們會進一步幫助你的。
看規則的明確聲明。 –
[複製所有xml節點並使用XSLT重命名少數節點](http:// stackoverflow。com/questions/10533543/copy-all-xml-nodes-and-rename-few-in-them-using-xslt) –
''屬性真的是'ref'還是實際上是'href'? –
Borodin