0

I have an xslt stylesheet for importing an XML file. There is a loop in that is concatenating a child node called "Note". I'm trying to get each note node separated by a new line, but I can't figure out the character to enter. Thanks in advance for the help. Here's my code:

xslt

<xsl:if test="Note">
    <xsl:call-template name="join">
        <xsl:with-param name="list" select="Note" />
        <xsl:with-param name="separator" select="';'" />
    </xsl:call-template>
</xsl:if>

<xsl:template name="join">
    <xsl:param name="list" />
    <xsl:param name="separator"/>

    <xsl:for-each select="$list">
        <xsl:value-of select="." />
        <xsl:if test="position() != last()">
            <xsl:value-of select="$separator" />
        </xsl:if>
    </xsl:for-each>
</xsl:template>

XML Node:

 <App action="A" id="65806">
      <BaseVehicle id="6664"/> 
      <BodyType id="5"/>  
      <Note>Upgrade</Note>
      <Note>replacement unit comes with a new dustcover / bumper assembly.</Note>
      <Qty>2</Qty>
      <PartType id="7584"/>  
      <Position id="30"/> 
 </App>

Expected Output

Currently...

 Upgrade;replacement unit comes with a new dustcover / bumper assembly.

Trying to get it to look like...

 Upgrade
 replacement unit comes with a new dustcover / bumper assembly.
Paully
  • 13
  • 5

1 Answers1

1

You still haven't shown us an XSLT we can run as is. I guess you want to change:

<xsl:with-param name="separator" select="';'" />

to:

<xsl:with-param name="separator" select="'&#10;'" />

or possibly (for Windows):

<xsl:with-param name="separator" select="'&#13;&#10;'" />
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • Don't try outputting ` ` - it will appear explicitly in the serialized output as ` ` or ` `. – Michael Kay Feb 17 '17 at 09:35
  • 1
    Then it's wrong. The serialization spec says "A consequence of this rule is that certain characters MUST be output as character references, to ensure that they survive the round trip through serialization and parsing. Specifically, CR, NEL and LINE SEPARATOR characters in text nodes MUST be output respectively as " ", "…", and "
", or their equivalents;..." (That's 2.0, but you can deduce the same rule for 1.0 although it's less explicit.) – Michael Kay Feb 17 '17 at 13:15
  • @MichaelKay Surely you're not suggesting that the output of Saxon is wrong? Anyway, I have looked up the passage you quote: it's listed under [XML Output Method](https://www.w3.org/TR/xslt-xquery-serialization/#xml-output). I think it goes without saying that the output method contemplated here is text. – michael.hor257k Feb 17 '17 at 14:40
  • I didn't see an xsl:output declaration but from the context I guess you're probably right that it's method="text" (or if not, it probably should be). – Michael Kay Feb 17 '17 at 16:46