You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by David Balch <da...@continuing-education.oxford.ac.uk> on 2004/05/10 15:59:17 UTC
Problem with a $PARAM in a simple javascript extension
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
Re: Problem with a $PARAM in a simple javascript extension
Posted by Henry Zongaro <zo...@ca.ibm.com>.
Hi, David.
You wrote on 2004-05-10 09:59:17 AM:
> 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".
I was trying to reproduce your problem, but I'm running into problems
at an early stage (most likely due of my lack of experience with extension
functions). Could I ask you to post a complete test case?
Thanks,
Henry
------------------------------------------------------------------
Henry Zongaro Xalan development
IBM SWS Toronto Lab T/L 969-6044; Phone +1 905 413-6044
mailto:zongaro@ca.ibm.com