New line separator for xslt/xml

2019-09-11 18:55发布

问题:

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.

回答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;'" />


标签: xml xslt