parameters in a search with match

Discussion in 'XML' started by Iain, Dec 9, 2003.

  1. Iain

    Iain Guest

    I've got some XLST which extracts some stuff from a config file. it works
    nicely. Now I want to make it work with a parameter

    My original attempt looked like (fragment)

    <xsl:param name="StyleName" />

    <xsl:template match="/Vendor/Style[@Name=$StyleName]" >

    And failed. (replace $StyleName in the above with a real style name and it
    works correctly). Eventually, I came up with this ...

    <xsl:param name="StyleName" />

    <xsl:template match="/Vendor" >

    <xsl:for-each select="Style[@Name=$StyleName]" >

    Which works also. But WHY won't it work with the match?

    Iain

    PS. I claim no skill in these areas - xslt/xpath and their friends are NOT
    pellicidly clear.
     
    Iain, Dec 9, 2003
    #1
    1. Advertising

  2. A match pattern cannot have a variable/parameter references in XSLT 1.0
    because this might lead to circular definitions (the referenced xsl:variable
    may have xsl:apply-templates in its body and the template that references
    this variable may be applied ...)

    The workaround is the following:

    Instead of:

    match = "aPatternWithVariableReference"

    use:

    <xsl:template match="correctPattern">
    <xsl:if test="someConditionWithTheVariableReference">
    <!-- The whole processing goes only here -->
    </xsl:if>
    </xsl:template>

    As you can see, this would be equivalent to:

    <xsl:template
    match="correctPattern[someConditionWithTheVariableReference]">
    <!-- Whatever processing should be performed -->
    </xsl:template>

    if the latter were allowed.

    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL


    "Iain" <> wrote in message
    news:WvpBb.989$...
    > I've got some XLST which extracts some stuff from a config file. it works
    > nicely. Now I want to make it work with a parameter
    >
    > My original attempt looked like (fragment)
    >
    > <xsl:param name="StyleName" />
    >
    > <xsl:template match="/Vendor/Style[@Name=$StyleName]" >
    >
    > And failed. (replace $StyleName in the above with a real style name and

    it
    > works correctly). Eventually, I came up with this ...
    >
    > <xsl:param name="StyleName" />
    >
    > <xsl:template match="/Vendor" >
    >
    > <xsl:for-each select="Style[@Name=$StyleName]" >
    >
    > Which works also. But WHY won't it work with the match?
    >
    > Iain
    >
    > PS. I claim no skill in these areas - xslt/xpath and their friends are

    NOT
    > pellicidly clear.
    >
    >
     
    Dimitre Novatchev, Dec 9, 2003
    #2
    1. Advertising

  3. Iain

    Iain Guest

    Thanks!

    Iain
    "Dimitre Novatchev" <> wrote in message
    news:br5a8n$28oqvd$-berlin.de...
    > A match pattern cannot have a variable/parameter references in XSLT 1.0
    > because this might lead to circular definitions (the referenced

    xsl:variable
    > may have xsl:apply-templates in its body and the template that references
    > this variable may be applied ...)
    >
    > The workaround is the following:
    >
    > Instead of:
    >
    > match = "aPatternWithVariableReference"
    >
    > use:
    >
    > <xsl:template match="correctPattern">
    > <xsl:if test="someConditionWithTheVariableReference">
    > <!-- The whole processing goes only here -->
    > </xsl:if>
    > </xsl:template>
    >
    > As you can see, this would be equivalent to:
    >
    > <xsl:template
    > match="correctPattern[someConditionWithTheVariableReference]">
    > <!-- Whatever processing should be performed -->
    > </xsl:template>
    >
    > if the latter were allowed.
    >
    > =====
    > Cheers,
    >
    > Dimitre Novatchev.
    > http://fxsl.sourceforge.net/ -- the home of FXSL
    >
    >
    > "Iain" <> wrote in message
    > news:WvpBb.989$...
    > > I've got some XLST which extracts some stuff from a config file. it

    works
    > > nicely. Now I want to make it work with a parameter
    > >
    > > My original attempt looked like (fragment)
    > >
    > > <xsl:param name="StyleName" />
    > >
    > > <xsl:template match="/Vendor/Style[@Name=$StyleName]" >
    > >
    > > And failed. (replace $StyleName in the above with a real style name and

    > it
    > > works correctly). Eventually, I came up with this ...
    > >
    > > <xsl:param name="StyleName" />
    > >
    > > <xsl:template match="/Vendor" >
    > >
    > > <xsl:for-each select="Style[@Name=$StyleName]" >
    > >
    > > Which works also. But WHY won't it work with the match?
    > >
    > > Iain
    > >
    > > PS. I claim no skill in these areas - xslt/xpath and their friends are

    > NOT
    > > pellicidly clear.
    > >
    > >

    >
    >
     
    Iain, Dec 9, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hiwa
    Replies:
    0
    Views:
    640
  2. Victor
    Replies:
    2
    Views:
    649
    Victor
    May 17, 2004
  3. ekzept
    Replies:
    0
    Views:
    373
    ekzept
    Aug 10, 2007
  4. Abby Lee
    Replies:
    5
    Views:
    419
    Abby Lee
    Aug 2, 2004
  5. John Gordon
    Replies:
    13
    Views:
    490
    Ian Kelly
    Dec 20, 2011
Loading...

Share This Page