1

Using Saxon parser freebie.

This is a snip of a larger XML file.

<osmChange>
  <modify>
    <node id="28377390">
      <tag k="name" v="Holywell"/>
      <tag k="public_transport" v="station"/>
      <tag k="railway" v="station"/>
    </node>
        <node id="168325631">
      <tag k="name" v="Whitecraigs"/>
      <tag k="public_transport" v="station"/>
      <tag k="railway" v="station"/>
    </node>
  </modify>
</osmChange>

This Xpath:

<xsl:sequence select="$OSM_OSC/osmChange/./modify/(node|way)[tag[@k='railway'][@v='station']]/tag[@k='name']"/>

Returns this, as expected.

<tag k="name" v="Whitecraigs"/>
<tag k="name" v="Holywell"/>

How do I get it to return just the actual names?

Whitecraigs
Holywell

I thought adding /@v to the end would be the solution:

<xsl:sequence select="$OSM_OSC/osmChange/./modify/(node|way)[tag[@k='railway'][@v='station']]/tag[@k='name']/@v"/>

However it returns a long-winded error message:

java.lang.UnsupportedOperationException: copy() applied to attribute node
at net.sf.saxon.tree.tiny.TinyAttributeImpl.copy(TinyAttributeImpl.java:259)
at net.sf.saxon.serialize.UncommittedSerializer.append(UncommittedSerializer.java:207)
at net.sf.saxon.event.ProxyReceiver.append(ProxyReceiver.java:200)
at net.sf.saxon.serialize.PrincipalOutputGatekeeper.append(PrincipalOutputGatekeeper.java:101)

Etc...

4
  • If you want a sequence of string values I would try <xsl:sequence select="osmChange/modify/(node|way)[tag[@k='railway'][@v='station']]/tag[@k='name']/@v/string()"/>. The error seems odd but it is hard to tell whether it is caused by trying to output the attribute nodes outside of a parent element container or by some bug in Saxon. Commented Jun 10 at 15:26
  • Trying to output attribute node(s) as part of a document should raise w3.org/TR/xslt-30/#err-XTDE0420 so something is wrong in Saxon, I would say, with the error you get, even if you haven't shown the context of the xsl:sequence selecting the two attribute nodes. But try to access the string values with the shown /@v/string() and you should get your two values Whitecraigs Holywell, I think, even with that bug/quirk in Saxon. Commented Jun 10 at 15:36
  • 2
    If you want to serialize (=write to the output) the values of those attributes, then use xsl:value-of instead of xsl:sequence. Commented Jun 10 at 15:40
  • 1
    BTW, I believe your xsl:sequence instruction would work if it were a child of some element (well, sort of work: an element cannot have two attributes with the same name, so the result would be something like <elem v="Whitecraigs"/>). Trying to output attributes without a parent element should result in an error, though I am not convinced that's the best error message. Commented Jun 10 at 16:39

1 Answer 1

2

Well, yes, it's a lousy error message - I will see if I can reproduce it.

The actual error is that you are trying to serialize attribute nodes without a containing element. I'm not sure what output method you are using, or exactly where the xsl:sequence instruction fits into the overall code, but I would suggest extracing the string value of the attributes directly by a call on string - use /string(@v) in place of /@v.

I have raised this as a Saxon issue at https://saxonica.plan.io/issues/6818 and the next maintenance release will give you a proper error message.

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.