2012-03-14 53 views

回答

1

使用

substring-before(/*/elem[1]/@attr, '
') 

下面是一個XSLT - 基於驗證

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

<xsl:template match="/"> 
    <xsl:copy-of select="substring-before(/*/elem[1]/@attr, '&#x0A;')"/> 
</xsl:template> 
</xsl:stylesheet> 

當這個變換所提供的XML文檔施加(校正爲良好形成!!! ):

<doc> 
    <elem attr="firstLine &#x0a; secondLine"/> 
    <elem attr="1stLine"/> 
</doc> 

它評估XPat H表達並輸出該評價的結果:

firstLine