1

Using the latest Saxon parser.

This is a snip of a larger XML file.

<osm>
    <node id="38275590">
        <tag k="name" v="Wimbledon"/>
    </node>
    <node id="28377390">
        <tag k="name" v="Westminster"/>
    </node>
    <node id="168325631">
        <tag k="name" v="Brixton"/>
    </node>
</osm>

This xslt/Xpath:

<xsl:template match="osm">  
    <xsl:result-document href="{'Underground_Now.txt'}">
        <xsl:value-of select="node[tag[@k='railway'][@v='station']]/tag[@k='name']/concat(string(@v),'&#xa;')"/>
    </xsl:result-document>
</xsl:template> 

Returns this (I've used a bullet-point to indicate a space).

Wimbledon
•Westminster
•Brixton

Why is it adding a whitespace to the beginning of each line? Note: It isn't present in the first string.

Even if I remove the linefeed it returns this:

•Westminster•Brixton

I've tried setting:

<xsl:output indent="no"/>

I've tried incorporating normalize-space() in various forms, such as:

/concat(normalize-space(string(@v)),'&#xa;')

...but it produces the same output.

3
  • The answer from @michael.hor257k is correct. I would suggest writing <xsl:value-of select="node[tag[@k='railway'][@v='station']]/tag[@k='name']" separator="&#xa;"/>. Commented Jun 12 at 20:39
  • @MichaelKay Does the order of parameters make a difference? Commented Jun 14 at 14:28
  • @DaveF XSLT itself is XML, and what you call "parameters" are actually attributes. The order of attributes is by definition insignificant: w3.org/TR/2008/REC-xml-20081126/#sec-starttags Commented Jun 14 at 20:12

1 Answer 1

2

The xsl:value-of instruction has an optional separator attribute.

If the separator attribute is present, then the effective value of this attribute is used to separate adjacent items in the result sequence, as described in 5.7.2 Constructing Simple Content. In the absence of this attribute, the default separator is a single space (#x20) when the content is specified using the select attribute, or a zero-length string when the content is specified using a sequence constructor.
https://www.w3.org/TR/xslt-30/#value-of

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.