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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

double nested transformations with xsl

Status
Not open for further replies.

BPMan

Programmer
Jun 25, 2002
163
US
essentially i have and xml file that looks like this

<?xml version=&quot;1.0&quot;?>
<test parameters id=&quot;01&quot;/>
<Test id=&quot;stuff&quot;>
<Container id=&quot;999&quot; type=&quot;main&quot;>
<Step id=&quot;0&quot;></Step>
<Step id=&quot;1&quot;></Step>
<Step id=&quot;2&quot;></Step>
<Container id=&quot;000&quot; type=&quot;inside&quot;>more stuff here</Container>
<Step id=&quot;3&quot;></Step>
</Container>
</Test>

i am passing the node of Container with id=&quot;999&quot; into a transform and i want to treat that container different then Containers inside of it. i cannot figure out how to do this.

sample of what i am trying:

<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;
<xsl:eek:utput method=&quot;html&quot;/>
<xsl:template match=&quot;/&quot;>
<HTML>
<HEAD>
</HEAD>
<BODY>
<table>
<tr>
<td>Container</td>
<td width=&quot;&quot; nowrap=&quot;&quot;><xsl:value-of select=&quot;@id&quot;/></td>
</tr>
<xsl:apply-templates select=&quot;Step | Container&quot;/>

</table>


</BODY>
</HTML>
</xsl:template>

<xsl:template match=&quot;Container&quot;>
<tr>
<td>Container<td>
<td width=&quot;&quot; nowrap=&quot;&quot;><xsl:value-of select=&quot;@id&quot;/></td>
</tr>
</xsl:template>

<xsl:template match=&quot;Step&quot;>

<tr>
<td>Step</td>
<td width=&quot;&quot; nowrap=&quot;&quot;><xsl:value-of select=&quot;@id&quot;/></td>
</tr>
</xsl:template>

</xsl:stylesheet>

if i am not clear just ask and i will try to explain better what i am looking for
thanks so much...
i am very new to xml and xsl
 
How do you want the output to look? It's not clear to me from your style sheet.
 
I want it to dispaly the contents of whatever container node i give it, which can be containers or steps so when i run this on the Container 999 node i would get
Container 999
Step 0
Step 1
Step 2
Container 000
Step 3

but if i were to run it on the Container 000 node i would get
Container 000
All the steps and Containers in Container 000


I had it working so that no matter what node i passed in it would just display the info for Container 999 but that is not what i want.
thanks for your help
 
OK, I'm still not clear if you want to explicitly only process one node, or you want the style sheet to process all container nodes. Here's the style sheet to process a single node that you specificy. You can tweak the <td> tags with additional attributes as you need. Hope this helps.

<xsl:stylesheet version=&quot;1.0&quot;

xmlns:xsl=&quot;<xsl:eek:utput method=&quot;html&quot;/>
<xsl:template match=&quot;/&quot;>
<html>
<body>
<table>
<xsl:for-each select=&quot;//Container[@id='999']&quot;>
<tr><td>Container</td><td><xsl:apply-templates select=&quot;@id&quot;/></td></tr>
<xsl:for-each select=&quot;Step | Container&quot;>
<tr>
<xsl:choose>
<xsl:when test=&quot;self::Step&quot;>
<td>Step</td>
</xsl:when>
<xsl:eek:therwise>
<td>Container</td>
</xsl:eek:therwise>
</xsl:choose>
<td><xsl:apply-templates select=&quot;@id&quot;/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
<br/>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
 
ok i need to be more clear, i am sorry.
My program is being passed a node, here is what i know about the node:
It container.
inside the container there are steps and containers.
they all have id's
lets say this is my xml file
<?xml version=&quot;1.0&quot;?>
<test parameters id=&quot;01&quot;/>
<Test id=&quot;stuff&quot;>
<Container id=&quot;999&quot; type=&quot;main&quot;>
<Step id=&quot;0&quot;></Step>
<Step id=&quot;1&quot;></Step>
<Step id=&quot;2&quot;></Step>
<Container id=&quot;000&quot; type=&quot;inside&quot;>
<Step id=&quot;00&quot;></Step>
<Step id=&quot;01&quot;></Step>
<Container id=&quot;010&quot; type=&quot;insideb&quot;>
<Step id=&quot;000&quot;></Step>
</Container>
</Container>
<Step id=&quot;3&quot;></Step>
</Container>
</Test>

i have no idea what the ids are or how many of anything.
but if the node of container 999 was passed in this is what i would want to display:

Container 999
Step 0
Step 1
Step 2
Container 000
Step 3

if Container 000 was passed to me then this is what i would want to be displayed:

Container 000
Step 00
Step 01
Container 010

so essentially just the direct childs of whatever container is passed to me...
my problem is i don't know how to make it only output what is at that node, it outputs the highest level container no matter what...
thanks for all your help i hope this is more clear.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top