Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2006, 03:55 PM
Daniel Frey
Guest
 
Posts: n/a
Default dynamic matching

Hello

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

<xsl:stylesheet ...>
<xsl:param name="tomatch"/>
<xsl:template match="{$tomatch}">
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

  #2  
Old July 21st, 2006, 01:45 AM
Dimitre Novatchev
Guest
 
Posts: n/a
Default Re: dynamic matching

Search for FXSL

Cheers,
Dimitre Novatchev

"Daniel Frey" <qwer12341@gmx.chwrote in message
news:1153407464.669856.214880@p79g2000cwp.googlegr oups.com...
Quote:
Hello
>
I'd like to match a dynamic node, given as a parameter to the
stylesheet. Something like:
>
<xsl:stylesheet ...>
<xsl:param name="tomatch"/>
<xsl:template match="{$tomatch}">
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
>

  #3  
Old July 21st, 2006, 04:25 AM
Joe Kesselman
Guest
 
Posts: n/a
Default 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
  #4  
Old July 21st, 2006, 05:55 AM
Daniel Frey
Guest
 
Posts: n/a
Default 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:
Quote:
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
  #5  
Old July 21st, 2006, 05:55 AM
Daniel Frey
Guest
 
Posts: n/a
Default Re: dynamic matching

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

Daniel

Dimitre Novatchev schrieb:
Quote:
Search for FXSL
>
Cheers,
Dimitre Novatchev
>
"Daniel Frey" <qwer12341@gmx.chwrote in message
news:1153407464.669856.214880@p79g2000cwp.googlegr oups.com...
Quote:
Hello

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

<xsl:stylesheet ...>
<xsl:param name="tomatch"/>
<xsl:template match="{$tomatch}">
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
  #6  
Old July 21st, 2006, 02:25 PM
Dimitre Novatchev
Guest
 
Posts: n/a
Default 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:otherwise>
<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-matchinstruction -- 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.googlegro ups.com...
Quote:
Thanks for the hint Dimitre. How would FXSL help me doing that?
>
Daniel
>
Dimitre Novatchev schrieb:
>
Quote:
>Search for FXSL
>>
>Cheers,
>Dimitre Novatchev
>>
>"Daniel Frey" <qwer12341@gmx.chwrote in message
>news:1153407464.669856.214880@p79g2000cwp.googleg roups.com...
Quote:
Hello
>
I'd like to match a dynamic node, given as a parameter to the
stylesheet. Something like:
>
<xsl:stylesheet ...>
<xsl:param name="tomatch"/>
<xsl:template match="{$tomatch}">
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
>
>

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles