xml - How to output text node value line by line using xslt 1.0? -


i have xml file like:

<messages>    error message 1     error message 2  </messages> 

i have output as:

error 1:  error message 1  error 2: error message 2 

i'm using xslt 1.0, , tried:

<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">  <xsl:output method="html" omit-xml-declaration="yes"/>  <xsl:template match="messages">     <h3>error 1:</h3>     <xsl:value-of select="substring-before(./text(), '&#10;')"/>     <h3>error 2:</h3>     <xsl:value-of select="substring-after(./text(), '&#10;')"/> </xsl:template> </xsl:stylesheet> 

but returned me nothing...could me this? thanks!

you can use recursive template achieve this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">    <xsl:output method="html" omit-xml-declaration="yes"/>    <xsl:template match="messages" name="outputerror">     <xsl:param name="index" select="1"/>     <xsl:param name="source" select="text()"/>     <xsl:variable name="thisline" select="normalize-space(substring-before($source, '&#10;'))"/>     <xsl:variable name="therest" select="substring-after($source, '&#10;')"/>     <xsl:choose>       <xsl:when test="$thisline">         <h3>error <xsl:value-of select="$index"/>:</h3>         <span><xsl:value-of select="$thisline"/></span>         <xsl:call-template name="outputerror">           <xsl:with-param name="index" select="$index + 1"/>           <xsl:with-param name="source" select="$therest"/>         </xsl:call-template>       </xsl:when>       <xsl:when test="$therest">         <xsl:call-template name="outputerror">           <xsl:with-param name="index" select="$index"/>           <xsl:with-param name="source" select="$therest"/>         </xsl:call-template>       </xsl:when>     </xsl:choose>   </xsl:template> </xsl:stylesheet> 

i wrapped actual errors in <span> element separate them whitespace, can of course <p>, <div> or no element @ if prefer.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -