2015-05-29 74 views
0

我有XML文檔如下,XSLT:XML標籤中刪除某些文字

<footnote> 
    <p type="Footnote Text"> 
     <link ref="http://www.apple.com/accessibility/iphone/hearing.html"> 
     <c type="Hyperlink">http:.apple.com/accessibility/iphone/hearing.html 
     </c> 
     </link> 
    </s> 
    </p> 
</footnote> 

什麼,我需要做的是從XSLT我需要標籤中去掉該URL的子串。

實施例:

原始XML文檔這樣的,

<c type="Hyperlink">http:www.apple.com/accessibility/iphone/hearing.html 
</c> 

和我需要轉換如下:

<c type="Hyperlink">www.apple.com </c> 

我搜索XSLT inbuild功能刪除在某一子字符串,但我找不到這樣的功能。

你可以給我任何建議如何做到這一點?

回答

1

c元件可被轉換以這樣的方式

<xsl:template match="c"> 
    <xsl:copy> 
     <xsl:copy-of select="@*"/> 
     <xsl:variable name="sa" select="substring-after(.,':')"/> 
     <xsl:variable name="sb" select="substring-before($sa,'/')"/> 
     <xsl:value-of select="$sb"/> 
    </xsl:copy> 
</xsl:template> 

請注意,你的榜樣是不是一個有效的XML文件,有與關閉標籤的問題。