|
Subject: Re: [xsl] Key and document() problem ? From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 07 Oct 2008 12:37:13 -0400 |
I would like to construct a key based on a different document, but I saw that is was not going to work. So I'm going explain what I want to do, since now I have no idea how it could be done.
Here are two pieces of the document I'm working on :
...
The whole thing is about selecting the requests of the 2nd document according to their step in the first document. So, usually it was easy since I had a for-each loop for the steps. The "step" level was so preserved. ie, I calculate the sum of request/data/@value in each step. That would be 2394 for step 1 and 1969+5451 for step2.
Now my problem is that I don't have the for-each step loop, but I still have to sum request according to the step they are in.
I don't know if it's clear. I don't even see clearly myself how I could achieve this.
T:\ftemp>type job.xml <job> <universe> <monitor id="45995" timeout="10000"> <step id="1" timeout="4000"> <request id="1"/> </step> <step id="2" timeout="9000"> <request id="2"/> <request id="3"/> </step> <step id="3" timeout="6000"> <request id="2"/> <request id="3"/> </step> </monitor> </universe> </job>
T:\ftemp>type monitor.xml
<monitor id="45995">
<site>
<test id="36">
<request id="1">
<data id="4" value="2394"/>
</request>
<request id="2">
<data id="4" value="1969"/>
</request>
<request id="3">
<data id="4" value="5451"/>
</request>
</test>
</site>
</monitor>T:\ftemp>type victor1.out Step 1: (1) 2394 NO TIMEOUT [4000] Step 2: (2) 7420 NO TIMEOUT [9000] Step 3: (2) 7420 TIMEOUT [6000]
T:\ftemp>type victor2.out Step 1: (1) 2394 NO TIMEOUT [4000] Step 2: (2) 7420 NO TIMEOUT [9000] Step 3: (2) 7420 TIMEOUT [6000]
T:\ftemp>type victor1.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:variable name="job">job.xml</xsl:variable> <xsl:variable name="monitor">monitor.xml</xsl:variable>
</xsl:stylesheet> T:\ftemp>type victor2.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:variable name="job">job.xml</xsl:variable> <xsl:variable name="monitor">monitor.xml</xsl:variable>
<xsl:template match="/">
<xsl:for-each select="document($job)/job/universe/monitor/step">
<xsl:text/>Step <xsl:value-of select="@id"/>: (<xsl:text/>
<xsl:variable name="test-requests"
select="document($monitor)/monitor/site/test/request
[@id=current()/request/@id]"/>
<xsl:value-of select="count($test-requests)"/>
<xsl:text>) </xsl:text>
<xsl:variable name="sum-test-requests"
select="sum($test-requests/data/@value)"/>
<xsl:value-of select="$sum-test-requests"/>
<xsl:text> </xsl:text>
<xsl:choose>
<xsl:when test="$sum-test-requests > @timeout">
<xsl:text>TIMEOUT</xsl:text>
</xsl:when>
<xsl:otherwise>NO TIMEOUT</xsl:otherwise>
</xsl:choose>
<xsl:text/> [<xsl:value-of select="@timeout"/><xsl:text>]
</xsl:text>
</xsl:for-each>
</xsl:template></xsl:stylesheet> T:\ftemp>rem Done!
-- Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video sample lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg Video course overview: http://www.youtube.com/watch?v=VTiodiij6gE G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Key and document() problem ?, Emilise Victor | Thread | Re: [xsl] Key and document() proble, Emilise Victor |
| [xsl] Key and document() problem ?, Emilise Victor | Date | [xsl] How to substitute a portion o, Paul |
| Month |