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 4653
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 thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Johannes Lebek |
last post by:
Hi there,
somehow, I cannot access nodes that are stored in a variable. I'm using
Xalan 2.5.1 and the following commands:
================ BEGIN ====================
<xsl:variable...
|
by: Ramon M. Felciano |
last post by:
Helo all --
I'm trying to gain a deeper understand for what type of
semi-declarative programming can be done through XML and XPath/XSLT.
I'm looking at graph processing problems as a testbed for...
|
by: Claudio Jolowicz |
last post by:
Suppose you have this document:
<root>
<node id="1">
<node id="4"/>
<node id="5"/>
</node>
<node id="2"/>
<node id="3"/>
</root>
|
by: Oleg Konovalov |
last post by:
Hi,
I am new to XSLT, trying to significantly modify somebody
else's XSL. That is not 2.0.
I need to create min & max variable(s)
to be used in many templates and sub-templates
based on...
|
by: Ian Roddis |
last post by:
Hello,
I want to embed SQL type queries within an XML data record. The XML
looks something like this:
<DISPLAYPAGE>
<FIELD NAME="SERVER" TYPE="DROPDOWN">
<OPTION>1<OPTION>
<OPTION>2<OPTION>...
|
by: Sergey Dubinets |
last post by:
In effort to prioritize our goals we composed the list of random features
each of them may add value to set of XSLT tools offered from Microsoft.
1. XSLTc (Compiler for XSLT...
|
by: SamStamport |
last post by:
Hello,
I have coded a C# program that passes an argument list to my XSLT file. I get no errors, but I don't get any output either.
Here's what I want to do: pass a parameter that is an XPath...
|
by: jkmyoung |
last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools.
Attribute Value Template
Official W3C explanation and example
This is when you want to put dynamic values...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |