473,388 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

data inside the xml in order to match a template

Hi, I am trying to have a style sheet read an xml file that has some
tagged data inside of it that has the name of the section the syle
sheet should process, does anyone know how I can do this?? Thanks
greatly for any help, I really appreciate it. Below is an example of
what I am describing.

<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="../xml/dqm_general.dev.xsl"?>

<perldata>
<arguments>

<test>TEST 0003</test>

<file>capacity_count.xml</file>

<xsl>dqm_general.dev.xsl</xsl>
</arguments>

Now further on in the xml document there is a tagged section called
item with a key value = "TEST 003" in the xml as such below
<item key="TEST 0003"> ... </item>

I want the style sheet to be able to read the <argument>/<test> tag in
order to know which section to match / process. I basically want the
template match and select commands to use this TEST 003 value at
processing time. Any ideas? Thanks again for your help with this.

<!-- apply templates for the test found in test tag -->

<xsl:apply-templates select='hashref/item @key="{arguments/test}"'/>

<!-- test template to process -->

<xsl:template match='hashref/item[@key={arguments/test}]'>

Jul 20 '05 #1
7 1210

several ways, eg:

<!-- throw items away by default -->
<xsl:template match="item"/>

<!--don't throw this one away -->
<xsl:template match="item[@key=/perldata/arguments/test]">
do something with <xsl:value-of select="@key"/>
</xsl:template>

David
Jul 20 '05 #2


David,

Thank you so much! So simple, but was missing just not using quotes!
Thanks again as I was venturing in the <xsl:variable> tag world which
did not seem to work for me.. I was using the following.. maybe you can
comment on why this was not working? Eitherway I really appreciate the
help again. Your the best!

<xsl:template match="perldata">

<xsl:variable name="_test"
select="/perldata/arguments/test"/>

<html>
<basefont face="Verdana" size="2" />
<body>
<xsl:apply-templates select='hashref/item[@key="$_test"]'/>

</body>
</html>
</xsl:template>

<!-- template match -->

<xsl:template match='hashref/item[@key="$_test"]'>



*** Sent via Developersdex http://www.developersdex.com ***

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 20 '05 #3

@key="$_test"

that tests if the key attribute is equal to the string $_test

You want to test if it is equal to the variable $_test so

@key=$_test

<!-- template match -->

<xsl:template match='hashref/item[@key="$_test"]'>

This is similar but you can't just remove the " here as you can't use a
variable in an XSLT1 match pattern.

But since you have already filtered the apply-templates select you can
just have

<xsl:template match='hashref/item">

David
Jul 20 '05 #4
Thanks again david. If you wanted to be able to match using a regular
expression your key value how could you do that? I have used
starts-with before
but say I have the following and I want to filter only SUMMARY sections
that have the item key="e_result" value of true (see below). Is there
a good way to do this if say the key may not always be e_result but
could be g_result?

<item key="SUMMARY">
<hashref memory_address="0x8db9dec">
<item key="non_viewable">
<hashref memory_address="0x8e46cd4">
<item key="test_value">TEST+0003</item>
</hashref>
</item>
<item key="viewable">
<hashref memory_address="0x8e511a0">
<item key="a_name">RBCNCN-0855-CITG</item>
<item key="b_capacity">3910</item>
<item key="c_lower">4297.7</item>
<item key="d_upper">3501.9</item>
<item key="e_result">true</item>
</hashref>
</item>
</hashref>
</item>
</hashref>
</item>

so my template section would be as follows

<!-- syntax is wrong here, but concept is shown of what I am trying to
do -->
<xsl:template
match="//item[@key='SUMMARY']/key(matches(_result))='true'">

Jul 20 '05 #5
Thanks again david. If you wanted to be able to match using a regular
You are using XSLT2 draft? You could have said. XSLT as currently
specified doesn't have regular expressions at all. If you are using
xslt2 then the comment about variables not allowed in match patterns
doesn't apply.

<xsl:template
match="//item[@key='SUMMARY']/key(matches(_result))='true'">

There is never any point in starting a match pattern with // it never
does anytthing useful. It sometimes changes the default priority but
here it does nothing.

<xsl:template
match="item[@key='SUMMARY']//item[matches(@key,'_result')]'">

or in xslt1

<xsl:template
match="item[@key='SUMMARY']//item[contains(@key,'_result')]'">

as contains is equivalent to matches for this trivial regex of a fixed
string.

David

Jul 20 '05 #6
I am using IE 6.0 's built in XSLT translation is this considered xslt1
or xslt2?

Jul 20 '05 #7

xslt1
Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David Furey | last post by:
Hi I have an XML documnet and a XSLT document as shown below THe XSLT document brings back a filtered docmument that has the VendorName that starts with a particular sub-string This works as...
2
by: Soren Kuula | last post by:
Hi, I'm trying to teach myself a little XSL. I have made up an XML model of a consed list, like : <list> <car>a</car> <cdr> <list> <car>b</car>
3
by: Miguel J. Jiménez | last post by:
Hi, I have the following node: <node> Some text here with lots of inside it... </node> and I would like it to transfrom it using XSLT to the following: Some text<br/> here with</br> lots...
0
by: Sharon | last post by:
Hiya, I have this stylesheet (based on an example @ http://rdcpro.com/xmldev/filterandsort)which I'm trying to modify so that it will work for my own XML and I get some data but it doesn't appear...
4
by: Jon Paal | last post by:
I am passing an xml data file to a server control and need to sort the data. The data has three levels(tables). What is the recommended approach to do the sorting ? (using vb.net and asp.net...
20
by: Derek Hart | last post by:
For testing purposes, I need some code that will loop through all attributes and elements in an XML file, and replace the data with the element or attribute name? Does anybody have code that will...
6
by: Mag Gam | last post by:
Hi All, I am new to XML, and trying to extract some data from a file. The file looks like this: <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST>...
11
by: doulos05 | last post by:
I am working on an xml project that will contain numerous documents which will be edited by about 100-150 non-technical people on a regular basis. Because of this, I am trying to make it as simple...
4
by: Debbiedo | last post by:
My software program outputs an XML Driving Directions file that I need to input into an Access table (although if need be I can import a dbf or xls) so that I can relate one of the fields...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.