XSLTransformation problem

A

avnrao

Hi,

sorry if this is cross post.. I have a simple XSLTransformation which I am
trying to load it in XSLTransform class as indicated below

loading xsl :

XslTransform tran = new XslTransform();
tran.Load(@"C:\AV\DotNet Projects\ReplaceString.xsl");

but the problem is its always giving the following errors when I load..
1. '' is an invalid QName - I have kind of resolved this by using { } for
accessing params.
2. boolean(contains({$str},{$from}) is an invalid XPath expression. - i am
not sure why this is an invalid xpath.

please do help.

ReplaceString.xsl :
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:call-template name="replace-string">
<xsl:with-param name="str" select="Str"></xsl:with-param>
<xsl:with-param name="from" select="From"></xsl:with-param>
<xsl:with-param name="to" select="To"></xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="replace-string">
<xsl:param name="str"/>
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:if test="contains({$str},{$from})">
<xsl:call-template name="">
<xsl:with-param name="str" select="substring-before({$str},{$from})"/>
<xsl:with-param name="from" select="substring-after({$str},{$from})"/>
<xsl:with-param name="to" select="$to"/>
</xsl:call-template>
</xsl:if>
<xsl:value-of select="concat({$str},{$to})"/>
</xsl:template>
</xsl:stylesheet>

thank you,
Av.
 
D

Das Duck

Well this is an XSL question rather than a C#-question.

But to my knowledge the solution is very simple:
contains, substring-before, substring-after and concat are does not handle
params inclosed in {}. instead you would simply do this: concat($str, $to).

You would only use { and } in situations like this:
<xsl:element name="{concat($str, $to}">stuff in element</xsl:element>

What { and } does is to tell the XSL parser that everything in between is
XSL-commands of a kind. Why is that needed? Well in the displayed example
the parser would expect a valid QName and "concat($strm $to)" isn't - so by
using {} we tell the parser to use the result of the commands in the
brackets instead.

/rap
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,235
Latest member
Top Crypto Podcasts_

Latest Threads

Top