xsl-list
[Top] [All Lists]

RE: RE: XPath expression confusion

2006-01-12 17:47:18
Yes, "system" is the root node. I'll try Geert Josten's approach when I get to 
work tomorrow. If anyone could cast some more light on where I've gone wrong, I'd 
appreciate it.

Thanks.
--
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Xia Li <xli(_at_)galdosinc(_dot_)com>
Sent:     Thu, 12 Jan 2006 15:39:58 -0800
To:       <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject:  RE: [xsl] XPath expression confusion

I just checked the spec. It seems to me that I gave a wrong explanation
about what you might be wrong. The <xsl:otherwise> in your example should be equivalent to <xsl:when
test="not(system/components/component/requirement/@number .)">

So my guess is that something wrong with the path
"/system/components/component/requirement/@number". It seemed to give an
empty sequence.
Is the <system> a root node?


Lisa


-----Original Message-----
From: Xia Li [mailto:xli(_at_)galdosinc(_dot_)com] Sent: Thursday, January 12, 2006 2:53 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] XPath expression confusion

I think you need to use
<xsl:when test="not(/system/components/component/requirement/@number .)">
        <requirement><xsl:value-of select="." /></requirement>
</xsl:when?

to look for the <number> element which no item in the sequence
"/system/components/component/requirement/@number" would match.
The <xsl:otherwise> in your style sheet is equivalent to the condition

<xsl:when test="/system/components/component/requirement/@number != .">

That means if there exists an item in the sequence selected by
"/system/components/component/requirement/@number" that is not equal to
the current value of <number> in the iteration, the condition is always
true. That is why you output all the value of <number> elements.


Lisa



-----Original Message-----
From: cknell(_at_)onebox(_dot_)com [mailto:cknell(_at_)onebox(_dot_)com] Sent: Thursday, January 12, 2006 1:49 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] XPath expression confusion

I have two files structured like this:

File A
-------
<requirements>
 <requirement>
   <number />
     <requirement>
       <number />
       And so on to an arbitrary depth
     </requirement>
 </requirement>
</requirements>

File B
-------
<system>
 <components>
   <component>
     <requirement number="" />
     <requirement number="" />
     <requirement number="" />
   </component>
 </components>
</system>

There will be an arbitrary number of components, each with an arbitrary
number of requirements.

My goal is to produce a document containing all the requirement/number
elements from File A that don't have a matching requirement/@number in
File B.

My unsuccessful approach is represented in this stylesheet fragment:

<xsl:variable name="all-reqs"
select="document('requirements.xml')/requirements//requirement/number"
/>

 <xsl:template match="/">
   <un-assigned-reqs>
     <xsl:for-each select="$all-reqs">
       <xsl:choose>
         <xsl:when
test="/system/components/component/requirement/@number = ." />
         <xsl:otherwise>
           <requirement><xsl:value-of select="." /></requirement>
         </xsl:otherwise>
       </xsl:choose>
     </xsl:for-each>
   </un-assigned-reqs>
 </xsl:template>

It was my belief that the XPath expression in the test would search all
the number attribute values in the document for a value that matched the
value of the current iteration of the loop.
Instead, it seems that there are no matches, as I get one element output
for each iteration of the loop.

Can someone point out where I'm going wrong?

Thanks.

--
Charles Knell
cknell(_at_)onebox(_dot_)com - email

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--