xml - How to strip away carriage returns with XSLT only? -


i have xml code can ahve 2 forms :

form 1

<?xml version="1.0"> <info> </info> 

form 2

<?xml version="1.0"> <info>   <a href="http://server.com/foo">bar</a>   <a href="http://server.com/foo">bar</a> </info> 

from loop read each form of xml , pass xslt stylesheet.

xslt code

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="2.0">     <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>     <xsl:strip-space elements="*" />      <xsl:template match="*|@*|text()">        <xsl:apply-templates select="/info/a"/>     </xsl:template>       <xsl:template match="a">        <xsl:value-of select="concat(text(), ' ', @href)"/>        <xsl:text>&#13;</xsl:text>     </xsl:template> </xsl:stylesheet> 

and obtain :

  bar http://server.com/foo bar http://server.com/foo 

how can remove first empty line xslt only ?

from loop read each form of xml , pass xslt stylesheet.

may application execution of stylesheet on empty form (form 1) causes this. try handle executing stylesheet whether form not empty.

furthermore may want change stylesheet one:

<xsl:stylesheet      xmlns:xsl="http://www.w3.org/1999/xsl/transform"      version="2.0">      <xsl:output method="text"/>     <xsl:strip-space elements="*" />      <xsl:template match="info/a">         <xsl:value-of select="concat(normalize-space(.),              ' ',             normalize-space(@href))"/>             <xsl:if test="follwing-sibling::a">              <xsl:text>&#xa;</xsl:text>             </xsl:if>     </xsl:template>  </xsl:stylesheet> 

where normalize-space() used ensure input data has no unwanted spaces.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -