Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML XSLT and javascript - Selection of specific data

Status
Not open for further replies.

virtual4now

Programmer
Mar 30, 2006
3
US



I am sorry, I am very new to XML and have lost the help of someone who helped me write this code.

I have an XML file kinda like this:

<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="sort.xsl"?>
<index>
<data section="controlled">
<rms docKey="414-060" subType="2" projNbr="b12414"/>
<rms docKey="414-060" subType="2" projNbr="b12414"/>
</data>
<data section="lastFive">
<rms docKey="414-060" subType="2" projNbr="b12414"/>
<rms docKey="414-060" subType="2" projNbr="b12414"/>
</data>
<data section="current">
<rms docKey="414-060" subType="2" projNbr="b12414"/>
<rms docKey="414-060" subType="2" projNbr="b12414"/>
</data>
</index>



This JavaScript code runs when the page loads:


// This is hardcoded, but the config file could be generated from a user's options
sOptions = "<?xml version=\"1.0\"?>"
sOptions += "<config>"
sOptions += "<select>rms</select>"
sOptions += "<filter>*</filter>"
sOptions += "<group>@projNbr</group>"
sOptions += "<sort>@docKey</sort>";
sOptions += "<sort>@subType</sort>";
sOptions += "</config>"
// now, let's transform the xml and display it
display('all',sOptions, "@projNbr");



I have more to the code obviously including the display function and the XSL file, but my question may be able to be answered without it.

What I am trying to do is select only one of the three "data section" and then process the "rms" elements within that.

Right now the code works, but works on all of the "rms" elements without any reguard to the sections they are in.

Any help or pointers would be wonderful.

Thanks!

Tim





 
You'll need to change the XSL file (post for exact answer).

Depending on the XPath used to select the rms nodes, you'll need to change a line that looks like:

index/data/rms

to (eg selecting the 'controlled' section):

index/data[@section='controlled']/rms

The XPath might be different though, so post the xsl

Jon

"I don't regret this, but I both rue and lament it.
 
Thanks, I think I understand what you are saying. I wasn't in the office yesterday, and today either.

That part of the XSL is actually generated with the JavaScript I posted above. You will see a line in the JS

sOptions += "<select>rms</select>"

I would assume that this is what I would change it to:

sOptions += "<select>index/data[@section='controlled']/rms</select>"

Now, I do understand that that line doesn't say index/data/rms, but just says rms (and here is another bit of my inexperience) but can the code shoot straight to the rms without the full path in some cases, or I should I be looking elsewhere in the code to see where the complete path is listed?

I will try your suggestion in the bit of code above and if it doesn't make sense or work I will post my XSL code.

Thanks again,

Tim
 
Thank You, Thank You, Thank You!!

That worked wonders.... being new to XML/XSL this was stumping me and cost me days, I just needed this boost, now I am back on track and off to the rest of the backend code to build this file on the fly and the transformations to display it on the web...... most of it being the easy stuff for me!

Thanks again!

Tim
 
I'd investigate exactly how the javascript generates the XSL, would make more sense then, also you will be sure it's pulling from the correct place.

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top