0

I just started fiddling with XSL for the first time in order to create my own "view template" in some collector's software. In the code I'm trying to insert line-breaks as a separator whenever there are multiple entries instead of ", ", but I'm having trouble getting it right. I've read inserting " " should do the trick, but it only outputs a space for me. Also read about seemingly simpler options like [br] and [p], but those codes break the template when simply inserting them instead of the comma.

Hope you can help me pointing out where I'm going wrong, thanks in advance!

<xsl:for-each select="userdefinedvalues/userdefinedvalue[@fieldid='dfUserField100010']/values/value">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
thorb65
  • 2,696
  • 2
  • 27
  • 37
DoubleUD
  • 3
  • 1

1 Answers1

1

You can use this in your <xsl:text> element instead of the comma:

<xsl:text>&#x000D;&#x000A;</xsl:text>

The &# starts a character reference using a hexadecimal value. The value is the Unicode code point of the character you want to output. 000D is a carriage return, 000A is a newline. Depending on what the output needs, you may only need the newline.

G_H
  • 11,739
  • 3
  • 38
  • 82
  • Thanks for your answer! I tried to add the code and it still only output a space, unfortunately. Could it be that the program I'm using doesn't support multiple results within 1 field spread out over multiple lines? – DoubleUD Feb 17 '17 at 22:24
  • @DoubleUD What program are you using to view the output? Does the XSLT output XML, text or HTML? If the output gets interpreted by something, it might just turn newlines or other control characters into spaces. – G_H Feb 17 '17 at 23:00
  • I'm using a program called CLZ Game Collector. It's a fine program, but it's not very user-friendly regarding customization. Instead it encourages you to piece together your own codes files based on the templates already used by the program. Long story short, I think you've just confirmed my suspicion, I think that's exactly what's happening here. So I will try a nice workaround using the slash symbol instead of a comma. Anyway, many thanks for your time and help! – DoubleUD Feb 20 '17 at 00:01
  • @DoubleUD Huh, I think I actually used that program at some point. Maybe to keep progress of what I've completed? At some point I realized I won't have enough time in this life to finish all my games, so I gave up :D – G_H Feb 20 '17 at 05:34
  • Haha that's awesome! I'm kinda in the same boat too, but I'm not too involved in the current generation - too many reboots and sequels, not enough new concepts for my taste - so that might be my ticket to at least finishing a decent portion of the backlog :-) Thanks again for the help man! – DoubleUD Feb 23 '17 at 12:06