xml-xalan-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Balch <david.ba...@continuing-education.oxford.ac.uk>
Subject Problem with a $PARAM in a simple javascript extension
Date Mon, 10 May 2004 13:59:17 GMT
Hi,

I want to do simple regular expression matching on an attribute value, which
is passed to a javascript extension function as a parameter, but I can't get
it working :-(

The javascript seems to recieve the XPath location of the attribute, rather
than it's value. E.g. "org.apache.xml.utils.NodeVector@ee7a14" instead of
"P1".

Relevant parts of the XSL:
---------------8<-------------------------

    <xalan:component prefix="regexp" functions="match">
        <xalan:script lang="javascript">
        <![CDATA[

// JS Regexp
function match(str, re, flags){
    var match = new RegExp(re, flags);
    return match.test(str) +  ", " + str + ", " + re;
}

]]>
        </xalan:script>
    </xalan:component>

    <xsl:template match="text:h|text:p">
        <xsl:copy>
            <xsl:attribute name="text:style-name">
                <xsl:call-template name="get-style-name">
                    <xsl:with-param name="STYLE_NAME"
select="@text:style-name"/>
                </xsl:call-template>
            </xsl:attribute>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template name="get-style-name">
        <xsl:param name="STYLE_NAME"/>
        <xsl:value-of select="regexp:match($STYLE_NAME, 'P\d+')"/>
    </xsl:template>

---------------8<-------------------------



XML fragment:
---------------8<-------------------------
        <text:p text:style-name="P1">Morality</text:p>
---------------8<-------------------------



Output fragment:
---------------8<-------------------------
<text:p text:style-name="false, org.apache.xml.utils.NodeVector@ee7a14,
P\d+">Morality</text:p>
---------------8<-------------------------


Expected results:
---------------8<-------------------------
<text:p text:style-name="true, P1, P\d+">Morality</text:p>
---------------8<-------------------------

Any help would be most appreciated!

Cheers,
Dave.

PS: Output of org.apache.xalan.xslt.EnvironmentCheck attached.

-- 
David Balch.          | Web developer.
T: +44 (0)1865 286932 | Technology-Assisted Lifelong Learning.
F: +44 (0)1865 286922 | University of Oxford.
E: david.balch@conted.ox.ac.uk

TALL, OUDCE and the University of Oxford accept no legal responsibility for
the contents of this message. Any views or opinions presented are only those
of the author and not those of TALL, or OUDCE, or the University of Oxford.
If this email has come to you in error please delete it and any attachments



Mime
View raw message