This project is read-only.

Function to return XML

Developer
Sep 1, 2010 at 5:36 PM

Hello,

a new question :-)

I'm trying to implement a function (in partial class Helper) that would return an xml string to the xslt caller, but cannot navigate this with xsl:for-each.

First I call the function and put my string ina variable:

 

<xsl:variable name="rs" select="mdo:MyFunction()"></xsl:variable>                

 

Such function returns a string result, containing a simple xml like:

 

<root>
<item>1</item>
<item>2</item>
<item>3</item>
</root>

 

I then want to simply list those values:

 

<xsl:for-each select="msxsl:node-set($rs)//item">
{{.}}<br/>
</xsl:for-each>

 

but cannot get a result.

This should just work, isn't it?

 

 

 

Coordinator
Sep 1, 2010 at 7:21 PM

Hi,

No, your code is wrong. msxsl:node-set works only with result tree fragment, i.e. xml declared in as xsl:variable body. This is NOT regular string.

You can use XsltDb extension mdo:node-set($rs). This function can accept xml as string, an absolute URL or relative URL (if begins with ~).

Unfortunately, it does not work with result tree fragment :-). I'll fix it in next release.

Coordinator
Sep 10, 2010 at 11:22 AM

Alberto,

I've created good sample of processing XML strings. http://xsltdb.codeplex.com/wikipage?title=Google%20News

This sample shows how you can load Google News RSS and filter our all stuff you don't want to see on your site. I'm not sure this is legal but as a sample it makes sence.