RE: [xsl] question on paths

Subject: RE: [xsl] question on paths
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 27 May 2010 00:13:42 +0100
I'm sorry that you are having trouble understand the responses you were
given. I'm afraid I may just be repeating the same response in slightly
different words.

>
> I am writing this function:
> ---------------
> <xsl:function name="fnc:getPatientRolePath">
>     <xsl:param name="Version"/>
>     <xsl:choose>
>         <xsl:when test="$Version = '3.0'">
>             <xsl:
> select="/n1:Document/n1:recordTarget/n1:patientRole"/>
>         </xsl:when>
>         <xsl:otherwise>UNDEFINED</xsl:otherwise>
>     </xsl:choose>
> </xsl:function>

As I explained in my previous response, "xsl:" is not a valid XML element
name, so this won't even get past the XML parser.
> ---------------
> I am writing this function so as to create a variable
> patientRolePath to hold the value:
> /n1:Document/n1:recordTarget/n1:patientRole.

As David Carlisle explained in his response, you can't hold fragments of
XPath expressions in variables, you can only hold values. However, that's
fine: to do what you describe below, you don't need to hold the path in the
variable, you can hold the set of nodes selected by the path.

> This is because then I can use the variable name
> patientRolePath and append child nodes and get required
> values such as:
>
> $patientRolePath/id
> $patientRolePath/lastName
> $patientRolePath/firstName
>
> However this that function I can't seem to write it to return
> with the path.
> <xsl: select="/n1:Document/n1:recordTarget/n1:patientRole"/>
> is not valid

Correct, "xsl:" is not a valid element name.

As I explained before, it's useful to tell us what error messages you are
getting, rather than simply saying something doesn't work. Then we can
explain the error to you.

 HOWEVER <xsl:variable name="patientRole"
> select="/n1:Document/n1:recordTarget/n1:patientRole"/>
> written as a statement is valid. But does not return me anything.

A variable declaration on its own doesn't return anything. A reference to
the variable would return something, but a variable that is never referenced
is useless.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay

Current Thread