Re: [xsl] document nodes.

Subject: Re: [xsl] document nodes.
From: "rick@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 13 Dec 2024 00:59:58 -0000
You can cast the attribute to a string:



<xsl:message select="xs:string($struct/@title)"/>



From: Andre Cusson akhu01@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, December 12, 2024 7:44 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] document nodes.



Hi,



There is some Saxon/Oxygen behavior that I do not seem to grasp.

I made a simplified use case to present it.



I have an xml document (thingtest.xml) that looks somewhat like this:



<?xml version="1.0" encoding="UTF-8"?>
<thing id="main" title="something">
    <thing id="group1">...</thing>
    <thing id="group2">...</thing>
    <thing id="group3">...</thing>
</thing>



and I have a stylesheet (thingtest.xslt) that reads this file and tries to
"message" the value of the title attribute on the main (root) element, like:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:xs="http://www.w3.org/2001/XMLSchema";
    xmlns:math="http://www.w3.org/2005/xpath-functions/math";
    exclude-result-prefixes="xs math"
    version="3.0">

    <xsl:template match="/">
        <xsl:variable name="struct" select="doc('thingtest.xml')/*"/>
        <xsl:message select="$struct/@title"/>
    </xsl:template>
</xsl:stylesheet>



Now running this produces this error

[Saxon-PE] Error XTDE0420 while evaluating xsl:message at line 10 of
file:servercfg/thingtest.xslt: Cannot create an attribute node (title) whose
parent is a document node.

Mind you, $struct should not be a document mode as it is the child of a
document node.

Where it gets a little exotic for me is when I replace the message instruction
by either :

 <xsl:message select="'' || $struct/@title"/>

or

 <xsl:message select="string-join(($struct/@title))"/>

Then, it works fine.



I do not mind adding a null string if I have to, but better understanding why
may better contribute to my happiness.

What am I doing wrong this time ... ;)

Thank you,

Regards.

Current Thread