dynamic matching

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

    #1

    dynamic matching

    Hello

    I'd like to match a dynamic node, given as a parameter to the
    stylesheet. Something like:

    <xsl:styleshe et ...>
    <xsl:param name="tomatch"/>
    <xsl:template match="{$tomatc h}">
    Hallo
    </xsl:template>
    </xsl:stylesheet>

    However, this seems not to be so simple, as "{" and if I remove the
    parentesis the "$" are not allowed in the match value.

    Certainly, I could take this as a row xslt and pre-transform it with
    another script to merge the value of the variable into the {$tomatch}
    location. However, then I would need two steps, one to create the
    merged xslt, and another to transform the xml with it.

    Is there a way to get it simlier? Any idea how to match dynamic nodes
    given in parameters would be highly appreciated.

    Thanks in advance.
    Daniel Frey

  • Dimitre Novatchev

    #2
    Re: dynamic matching

    Search for FXSL

    Cheers,
    Dimitre Novatchev

    "Daniel Frey" <qwer12341@gmx. chwrote in message
    news:1153407464 .669856.214880@ p79g2000cwp.goo glegroups.com.. .
    Hello
    >
    I'd like to match a dynamic node, given as a parameter to the
    stylesheet. Something like:
    >
    <xsl:styleshe et ...>
    <xsl:param name="tomatch"/>
    <xsl:template match="{$tomatc h}">
    Hallo
    </xsl:template>
    </xsl:stylesheet>
    >
    However, this seems not to be so simple, as "{" and if I remove the
    parentesis the "$" are not allowed in the match value.
    >
    Certainly, I could take this as a row xslt and pre-transform it with
    another script to merge the value of the variable into the {$tomatch}
    location. However, then I would need two steps, one to create the
    merged xslt, and another to transform the xml with it.
    >
    Is there a way to get it simlier? Any idea how to match dynamic nodes
    given in parameters would be highly appreciated.
    >
    Thanks in advance.
    Daniel Frey
    >

    Comment

    • Joe Kesselman

      #3
      Re: dynamic matching

      This is related to the thread "expand parts of an xml, which is
      transformed by xslt to html". Either use the EXSLT
      dynamic-XPath-evaluation extensions (if available), or figure out a way
      to express your selection request in a form that lets you write an
      interpreter in XSLT to evaluate it.

      EXSLT is supported by many XSLT processors these days... but not all.
      Depending on what you're trying to do, that possible loss of portability
      may or may not be a problem.

      --
      () ASCII Ribbon Campaign | Joe Kesselman
      /\ Stamp out HTML e-mail! | System architexture and kinetic poetry

      Comment

      • Daniel Frey

        #4
        Re: dynamic matching

        Thanks Joe for the hint. I looked at EXSLT and tried node-set(),
        evaluate() and document(). But still, the parser does complain about
        "$" in the match value. I read in Michael Kays XSLT 2nd Edition that
        any sort of variable is disalowed in the match attribute to prevent
        circular definitions. So it seem that there is no way to use the match
        attribute.

        Maybe there is another way to achive the same result. I'd like to use a
        template to handle dynamic structures as described in my first post. Is
        there another way to handle dynamic matches?

        Daniel

        Joe Kesselman schrieb:
        This is related to the thread "expand parts of an xml, which is
        transformed by xslt to html". Either use the EXSLT
        dynamic-XPath-evaluation extensions (if available), or figure out a way
        to express your selection request in a form that lets you write an
        interpreter in XSLT to evaluate it.
        >
        EXSLT is supported by many XSLT processors these days... but not all.
        Depending on what you're trying to do, that possible loss of portability
        may or may not be a problem.
        >
        --
        () ASCII Ribbon Campaign | Joe Kesselman
        /\ Stamp out HTML e-mail! | System architexture and kinetic poetry

        Comment

        • Daniel Frey

          #5
          Re: dynamic matching

          Thanks for the hint Dimitre. How would FXSL help me doing that?

          Daniel

          Dimitre Novatchev schrieb:
          Search for FXSL
          >
          Cheers,
          Dimitre Novatchev
          >
          "Daniel Frey" <qwer12341@gmx. chwrote in message
          news:1153407464 .669856.214880@ p79g2000cwp.goo glegroups.com.. .
          Hello

          I'd like to match a dynamic node, given as a parameter to the
          stylesheet. Something like:

          <xsl:styleshe et ...>
          <xsl:param name="tomatch"/>
          <xsl:template match="{$tomatc h}">
          Hallo
          </xsl:template>
          </xsl:stylesheet>

          However, this seems not to be so simple, as "{" and if I remove the
          parentesis the "$" are not allowed in the match value.

          Certainly, I could take this as a row xslt and pre-transform it with
          another script to merge the value of the variable into the {$tomatch}
          location. However, then I would need two steps, one to create the
          merged xslt, and another to transform the xml with it.

          Is there a way to get it simlier? Any idea how to match dynamic nodes
          given in parameters would be highly appreciated.

          Thanks in advance.
          Daniel Frey

          Comment

          • Dimitre Novatchev

            #6
            Re: dynamic matching

            Hi Daniel,

            I was mislead by the wording: "match a dynamic node, given as a parameter ",
            which sounds as a good description what a higher-order xsl:function does --
            with the exception that we should say "apply-templates to a dynamic node,
            given as a parameter ".

            Reading your post for a second time I understand what you want. One way to
            achieve this is, supposing that the $tomatch parameter is defined as a
            single node, is to have the following template:

            <xsl:template match="node() | @*">

            <xsl:choose>
            <xsl:when test="generate-id() = generate-id($tomatch)">
            Hallo
            </xsl:when>
            <xsl:otherwis e>
            <xsl:apply-imports/>
            </xsl:otherwise>
            </xsl:choose>
            </xsl:template>


            You have to assure this template has the highest import-precedence and that
            any other templates are part of stylesheets imported by the stylesheet that
            contains the above template. Not very convenient, but possible to do.

            In XSLT 2.0 one can use the <xsl:next-matchinstructio n -- designed to
            eliminate the inconvenience of using <xsl:apply-importsin a case like
            this -- the overridden templates that are invoked can now be in the same
            stylesheet.

            Hope this helped.


            Cheers,
            Dimitre Novatchev


            "Daniel Frey" <qwer12341@gmx. chwrote in message
            news:1153458088 .180765.247800@ i3g2000cwc.goog legroups.com...
            Thanks for the hint Dimitre. How would FXSL help me doing that?
            >
            Daniel
            >
            Dimitre Novatchev schrieb:
            >
            >Search for FXSL
            >>
            >Cheers,
            >Dimitre Novatchev
            >>
            >"Daniel Frey" <qwer12341@gmx. chwrote in message
            >news:115340746 4.669856.214880 @p79g2000cwp.go oglegroups.com. ..
            Hello
            >
            I'd like to match a dynamic node, given as a parameter to the
            stylesheet. Something like:
            >
            <xsl:styleshe et ...>
            <xsl:param name="tomatch"/>
            <xsl:template match="{$tomatc h}">
            Hallo
            </xsl:template>
            </xsl:stylesheet>
            >
            However, this seems not to be so simple, as "{" and if I remove the
            parentesis the "$" are not allowed in the match value.
            >
            Certainly, I could take this as a row xslt and pre-transform it with
            another script to merge the value of the variable into the {$tomatch}
            location. However, then I would need two steps, one to create the
            merged xslt, and another to transform the xml with it.
            >
            Is there a way to get it simlier? Any idea how to match dynamic nodes
            given in parameters would be highly appreciated.
            >
            Thanks in advance.
            Daniel Frey
            >
            >

            Comment

            Working...