[xsl] Trouble passing XSL function a parameter

Subject: [xsl] Trouble passing XSL function a parameter
From: "C. Edward Porter cep@xxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 5 Nov 2015 15:49:04 -0000
I am attempting to write a function to parse and return the pseudo-attributes
of a PI. In doing so, I am having trouble passing parameters. I am using
oXygen 17 and SaxonPE 9.6.0.5. My XSL and the test data are below:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:xs="http://www.w3.org/2001/XMLSchema";
    xmlns:uspc="http://whatever.com";
    exclude-result-prefixes="xs uspc"
    version="2.0">

    <xsl:function name="uspc:parsePI">
        <xsl:param name="data" as="xs:string"/>
        <xsl:param name="att" as="xs:string"/>
        <xsl:variable name="searchstring">(<xsl:value-of
select="$att"/>=)('|")(.*?)(\2)</xsl:variable>
        <xsl:analyze-string select="$data" regex="$searchstring" flags="i">
            <xsl:matching-substring>
                <xsl:value-of select="regex-group(3)"/>
            </xsl:matching-substring>
        </xsl:analyze-string>
    </xsl:function>

    <xsl:template match="processing-instruction('uspc-end-add')">
        Contents: <xsl:value-of select="."/>
        <xsl:variable name="self" select="."/>
        SWS: <xsl:value-of select="uspc:parsePI($self, 'sws')"/>
    </xsl:template>

</xsl:stylesheet>


Test data:
<test>
<?uspc-end-add id="f104450-r0001"  sws="C139995_131101"  symbols="yes"?>
</test>

When I debug, it appears that the second parameter "att" is undefined in the
scope of the function. I'm not clear why this is the case.

I am aware that there is a saxon function that accomplishes this task,
unfortunately, our production environment isn't running Saxon, but is XSL2.0,
so I should be able to use my own function to accomplish this task.

Thanks in advance for any advice!

Regards,
Edward

Current Thread