PDA

View Full Version : XSLT 'xsl:analyze-string' doesn't work



Sanje2v
26th February 2011, 23:30
Hi all,
I am having trouble with 'xsl:analyze-string'. I have the following source XML:

<AUTHOR_CONTACT_INFORMATION>Plugin author can be reached at abc@yahoo.com for his email.</AUTHOR_CONTACT_INFORMATION>

And I am using the following XSLT:

<xsl:analyze-string select="AUTHOR_CONTACT_INFORMATION" regex="(abc@yahoo.com)">
<xsl:matching-substring>
<a href="{regex-group(1)}"><xsl:value-of select="regex-group(1)" /></a>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="." />
</xsl:non-matching-substring>
</xsl:analyze-string>

The idea is to replace email addresses and web links with HTML a href. (In the above example, I've just replaced RegEx expressions to make things easier) Using Qt4's QXmlQuery class as my XSLT processor gives me empty string. Using 'Altova XMLSpy' the above correctly displays the hyperlinked output. Qt4's conformance documentation says Qt4 supports 'xsl:analyze-string'. What am I doing wrong? Are there any working examples using 'xsl:analyze-string'?

wysota
27th February 2011, 08:53
See if the reference examples work: http://www.w3.org/TR/xslt20/#analyze-string

Sanje2v
27th February 2011, 12:35
Here's a simple example I pulled from the link:

XML:


<?xml version="1.0" encoding="UTF-8"?>
<abstract>Hello there!
This is just a test</abstract>

XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">

<xsl:template match="/">
<html>
<body>
<xsl:analyze-string select="abstract" regex="\n">
<xsl:matching-substring>
<br/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Output from Qt4 app:

<html>
<body/>
</html>

Output from Altova XMLSpy:

<html>
<body>Hello there!<br>This is just a test</body>
</html>

My version of qt is 4.7.0 (32-bit) Windows version downloaded from qt.nokia.com/products . I didn't compile the source myself. And if its relevent, I am running Windows 7 Home 64-bit.

wysota
27th February 2011, 15:10
If the reference example doesn't work then obviously that's a case which is not handled by Qt's XQuery implementation.

Sanje2v
27th February 2011, 23:27
Why does the XSLT Conformance Docs (http://doc.trolltech.com/main-snapshot/xmlprocessing.html#xslt-2-0) specifically show that it is supported?

Stating the obvious wasn't the answer I was looking forward to. What could be a work around for this (in XSLT 1.0 maybe)? Currently, as I have to output tags '<' and '>' by escaping them, I am using the following:
1. using xsl:value-of select= "replace(AUTHOR,_CONTACT_INFORMATION, '(abc@yahoo.com)', '&lt;a href=&quot;$1&quot;&gt;$1&lt;/a&gt;')"
2. then the output is parsed again in C++ code by replacing '&lt;' and '&gt;' with actual characters

wysota
28th February 2011, 00:16
Why does the XSLT Conformance Docs (http://doc.trolltech.com/main-snapshot/xmlprocessing.html#xslt-2-0) specifically show that it is supported?
It doesn't specify what exactly is supported. If you want, find if Qt has an autotest for analyze-string.