Hi,
I have an XML file similar to the following:
<!-- snippet -->
<selector key='USER/id' value='type1'/>
<selector key='USER/id' value='type2'/>
<selector key='USER/id' value='type3'/>
<options>
<USER>
<NAME>Bob</NAME>
<id>type1</id>
</USER>
<USER>
<NAME>Jane</NAME>
<id>type1</id>
</USER>
<USER>
<NAME>Bill</NAME>
<id>type2</id>
</USER>
<!-- ... -->
</options>
<!-- end snippet -->
What I would like to do using xslt is for each <selector> tag, look up
the tag(s) in <options> whose ids match the value of the node
distinguished by the selector's 'key' attribute, e.g. for the first
selector, I would like a node-set containing the users Bob and Jane, but
not Bill.
I need the path to the node (the selector 'key') to be specified in the
XML document, so I can't do it statically like:
<xsl:variable name="value" select="selector/@value"/>
<xsl:for-each select='options/USER/id=$value'>...</xsl:for-each>
I believe that also means I can't use xsl:key, since it must be
top-level and can't have variable names in its match attribute.
Is this possible with xslt or should I seek some other solution?
Regards,
--Mike 6 4492
Mike Grass wrote: I need the path to the node (the selector 'key') to be specified in the XML document
That's usually bad idea. XPath and XSLT don't support dynamic evaluation
of XPath expressions, so you task at ones becomes quite onerous just
because of poor design. Consider not using XPath in your data, use
traditional XML means to express relationship - hierarchy, element
names, IDs etc.
Is this possible with xslt or should I seek some other solution?
I'd go for two-step transformation - first generate XSLT stylesheet
(using XSLT again of course) with appropriate xsl:key definitions
according to selector keys and then run it.
--
Oleg Tkachenko [XML MVP] http://blog.tkachenko.com
Mike Grass wrote: I need the path to the node (the selector 'key') to be specified in the XML document
That's usually bad idea. XPath and XSLT don't support dynamic evaluation
of XPath expressions, so you task at ones becomes quite onerous just
because of poor design. Consider not using XPath in your data, use
traditional XML means to express relationship - hierarchy, element
names, IDs etc.
Is this possible with xslt or should I seek some other solution?
I'd go for two-step transformation - first generate XSLT stylesheet
(using XSLT again of course) with appropriate xsl:key definitions
according to selector keys and then run it.
--
Oleg Tkachenko [XML MVP] http://blog.tkachenko.com
Mike,
I haven't tried it, would a Custom Extension function work? http://support.microsoft.com/default...b;en-us;324899
Otherwise I agree with Oleg, I would find a different method to use...
Hope this helps
Jay
"Mike Grass" <mi**@accessdata.com> wrote in message
news:ef**************@TK2MSFTNGP11.phx.gbl... Hi,
I have an XML file similar to the following: <!-- snippet --> <selector key='USER/id' value='type1'/> <selector key='USER/id' value='type2'/> <selector key='USER/id' value='type3'/> <options> <USER> <NAME>Bob</NAME> <id>type1</id> </USER> <USER> <NAME>Jane</NAME> <id>type1</id> </USER> <USER> <NAME>Bill</NAME> <id>type2</id> </USER> <!-- ... --> </options> <!-- end snippet -->
What I would like to do using xslt is for each <selector> tag, look up the tag(s) in <options> whose ids match the value of the node distinguished by the selector's 'key' attribute, e.g. for the first selector, I would like a node-set containing the users Bob and Jane, but not Bill.
I need the path to the node (the selector 'key') to be specified in the XML document, so I can't do it statically like: <xsl:variable name="value" select="selector/@value"/> <xsl:for-each select='options/USER/id=$value'>...</xsl:for-each>
I believe that also means I can't use xsl:key, since it must be top-level and can't have variable names in its match attribute.
Is this possible with xslt or should I seek some other solution?
Regards, --Mike
Mike,
I haven't tried it, would a Custom Extension function work? http://support.microsoft.com/default...b;en-us;324899
Otherwise I agree with Oleg, I would find a different method to use...
Hope this helps
Jay
"Mike Grass" <mi**@accessdata.com> wrote in message
news:ef**************@TK2MSFTNGP11.phx.gbl... Hi,
I have an XML file similar to the following: <!-- snippet --> <selector key='USER/id' value='type1'/> <selector key='USER/id' value='type2'/> <selector key='USER/id' value='type3'/> <options> <USER> <NAME>Bob</NAME> <id>type1</id> </USER> <USER> <NAME>Jane</NAME> <id>type1</id> </USER> <USER> <NAME>Bill</NAME> <id>type2</id> </USER> <!-- ... --> </options> <!-- end snippet -->
What I would like to do using xslt is for each <selector> tag, look up the tag(s) in <options> whose ids match the value of the node distinguished by the selector's 'key' attribute, e.g. for the first selector, I would like a node-set containing the users Bob and Jane, but not Bill.
I need the path to the node (the selector 'key') to be specified in the XML document, so I can't do it statically like: <xsl:variable name="value" select="selector/@value"/> <xsl:for-each select='options/USER/id=$value'>...</xsl:for-each>
I believe that also means I can't use xsl:key, since it must be top-level and can't have variable names in its match attribute.
Is this possible with xslt or should I seek some other solution?
Regards, --Mike
You could use a variable in the xml file and send the
xpath query to the xml file.
Sonu -----Original Message----- Hi,
I have an XML file similar to the following: <!-- snippet --> <selector key='USER/id' value='type1'/> <selector key='USER/id' value='type2'/> <selector key='USER/id' value='type3'/> <options> <USER> <NAME>Bob</NAME> <id>type1</id> </USER> <USER> <NAME>Jane</NAME> <id>type1</id> </USER> <USER> <NAME>Bill</NAME> <id>type2</id> </USER> <!-- ... --> </options> <!-- end snippet -->
What I would like to do using xslt is for each <selector>
tag, look upthe tag(s) in <options> whose ids match the value of the
nodedistinguished by the selector's 'key' attribute, e.g. for
the firstselector, I would like a node-set containing the users
Bob and Jane, butnot Bill.
I need the path to the node (the selector 'key') to be
specified in theXML document, so I can't do it statically like: <xsl:variable name="value" select="selector/@value"/> <xsl:for-each
select='options/USER/id=$value'>...</xsl:for-each> I believe that also means I can't use xsl:key, since it
must betop-level and can't have variable names in its match
attribute. Is this possible with xslt or should I seek some other
solution? Regards, --Mike .
You could use a variable in the xml file and send the
xpath query to the xml file.
Sonu -----Original Message----- Hi,
I have an XML file similar to the following: <!-- snippet --> <selector key='USER/id' value='type1'/> <selector key='USER/id' value='type2'/> <selector key='USER/id' value='type3'/> <options> <USER> <NAME>Bob</NAME> <id>type1</id> </USER> <USER> <NAME>Jane</NAME> <id>type1</id> </USER> <USER> <NAME>Bill</NAME> <id>type2</id> </USER> <!-- ... --> </options> <!-- end snippet -->
What I would like to do using xslt is for each <selector>
tag, look upthe tag(s) in <options> whose ids match the value of the
nodedistinguished by the selector's 'key' attribute, e.g. for
the firstselector, I would like a node-set containing the users
Bob and Jane, butnot Bill.
I need the path to the node (the selector 'key') to be
specified in theXML document, so I can't do it statically like: <xsl:variable name="value" select="selector/@value"/> <xsl:for-each
select='options/USER/id=$value'>...</xsl:for-each> I believe that also means I can't use xsl:key, since it
must betop-level and can't have variable names in its match
attribute. Is this possible with xslt or should I seek some other
solution? Regards, --Mike . This discussion thread is closed Replies have been disabled for this discussion. Similar topics
1 post
views
Thread by Johannes Lebek |
last post: by
|
6 posts
views
Thread by Ramon M. Felciano |
last post: by
|
5 posts
views
Thread by Claudio Jolowicz |
last post: by
|
1 post
views
Thread by Oleg Konovalov |
last post: by
|
3 posts
views
Thread by Ian Roddis |
last post: by
|
1 post
views
Thread by Sergey Dubinets |
last post: by
| | | | | | | | | | | | |