XSLTransformation problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • avnrao

    XSLTransformation problem

    Hi,

    sorry if this is cross post.. I have a simple XSLTransformati on 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\Replac eString.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(contain s({$str},{$from }) is an invalid XPath expression. - i am
    not sure why this is an invalid xpath.

    please do help.

    ReplaceString.x sl :
    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:styleshe et 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="substri ng-before({$str},{ $from})"/>
    <xsl:with-param name="from" select="substri ng-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.


  • Das Duck

    #2
    Re: XSLTransformati on problem

    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($st rm $to)" isn't - so by
    using {} we tell the parser to use the result of the commands in the
    brackets instead.

    /rap

    "avnrao" <avn@newsgroups .com> wrote in message
    news:OtwkiL#TEH A.3420@TK2MSFTN GP09.phx.gbl...[color=blue]
    > Hi,
    >
    > sorry if this is cross post.. I have a simple XSLTransformati on 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\Replac eString.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(contain s({$str},{$from }) is an invalid XPath expression. - i am
    > not sure why this is an invalid xpath.
    >
    > please do help.
    >
    > ReplaceString.x sl :
    > <?xml version="1.0" encoding="UTF-8" ?>
    > <xsl:styleshe et 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="substri ng-before({$str},{ $from})"/>
    > <xsl:with-param name="from" select="substri ng-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.
    >
    >[/color]


    Comment

    Working...