2015-01-07 36 views
0
<article> 
    <articleInfo> 
     <journalCode>ABC</journalCode> 
     <articleNo>456</articleNo> 
    </articleInfo> 
    <body> 
     <heading><!--This article contain 1 heading-->Heading 1</heading> 
     <p>α-index</p> 
     <p>This is para 2</p> 
     <p>This is para 3</p> 
     <p>This is para 4</p> 
     <p>This is para 5</p> 
    </body> 
</article> 

如何更改使用XSLT 我也想更換一個索引來α提前感謝註釋文本如何使用XSLT轉換更改註釋

+0

<?XML版本= 「1.0」 編碼= 「UTF-8」?> 的 \t的 \t的 \t \t的 \t \t 這個標題是文章的唯一1個標題 \t LiXin

+0

我希望我的輸出是這樣的

\t \t \t ABC \t \t \t \t \t \t <! - 此標題是唯一1個標題中的文章 - >標題1 \t \t

α -index

\t \t

這是第2段

\t \t

這是第3段

\t \t

這是第4

\t \t

這是第5

\t
LiXin

+0

其實,你可以編輯你的問題把你的代碼和輸出。順便說一句,在你的預期產出中,'α'是什麼。這不是一個合適的逃脫角色。 –

回答

0

您可以使用以下XSLT:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" indent="yes"/> 
<xsl:strip-space elements="*"/> 

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

<xsl:template match="text()[contains(.,'α-index')]"> 
    <xsl:value-of select="replace(., 'α-index', 'index 1')"/> 
</xsl:template> 

<xsl:template match="comment()"> 
    <xsl:comment>This heading was the only 1 heading in article</xsl:comment> 
</xsl:template> 
</xsl:stylesheet> 

您可以按照您的要求更改第二個模板(匹配文本())。