xsl-list
[Top] [All Lists]

RE: How can I get context node in this complex expresion? (current( ) didn't work)

2005-05-04 15:07:08
Yes, ROW has only 1 COB_ID.

How can I set XPATH version?

Let me explain you the problem I need to solve (in a simplified manner).

I have this XML:

<coberturas>
  <ROWSET>
    <ROW>
      <COB_ID>10</COB_ID>
      <COB_DESC>Description 0</COB_DESC>
    </ROW>
    <ROW>
      <COB_ID>2</COB_ID>
      <COB_DESC>Description 1</COB_DESC>
    </ROW>
    <ROW>
      <COB_ID>3</COB_ID>
      <COB_DESC>Description 2</COB_DESC>
    </ROW>
    <ROW>
      <COB_ID>5</COB_ID>
      <COB_DESC>Description 3</COB_DESC>
    </ROW>
    <ROW>
      <COB_ID>27</COB_ID>
      <COB_DESC>Description 4</COB_DESC>
    </ROW>
  </ROWSET>
</coberturas>
<cob_excluyentes>
  <ROWSET>
    <ROW>
      <CAD_ID>3</CAD_ID>
      <COB_ID>2</COB_ID>
    </ROW>
    <ROW>
      <CAD_ID>5</CAD_ID>
      <COB_ID>27</COB_ID>
    </ROW>
    <ROW>
      <CAD_ID>2</CAD_ID>
      <COB_ID>3</COB_ID>
    </ROW>
    <ROW>
      <CAD_ID>4</CAD_ID>
      <COB_ID>5</COB_ID>
    </ROW>
  </ROWSET>
</cob_excluyentes>
<cad_excluyentes>
  <ROWSET>
    <ROW>
      <CAD_ORI_ID>2</CAD_ORI_ID>
      <CAD_REL_ID>5</CAD_REL_ID>
    </ROW>
    <ROW>
      <CAD_ORI_ID>3</CAD_ORI_ID>
      <CAD_REL_ID>4</CAD_REL_ID>
    </ROW>
    <ROW>
      <CAD_ORI_ID>4</CAD_ORI_ID>
      <CAD_REL_ID>3</CAD_REL_ID>
    </ROW>
    <ROW>
      <CAD_ORI_ID>5</CAD_ORI_ID>
      <CAD_REL_ID>2</CAD_REL_ID>
    </ROW>
  </ROWSET>
</cad_excluyentes>

That XML is enclosed between a topmost tag. All XML comes from a database, so 
the only thing I can modify is the fields returned, not the XML structure. The 
explanation of each XML block is as follows:

1. <coberturas>
        The data I want to display
2. <cob_excluyentes>
        Represents the CAD that corresponds to this COB
3. <cad_excluyentes>
        Represents exclusions. That is, CAD_ID = 2 cannot be together with 
CAD_ID = 5

From <coberturas> above, this will be printed on screen:

Option 1:
- Description 0
- Description 1
- Description 2

Option 2:
- Description 0
- Description 3
- Description 4

Any idea to solve this?

Thanks
Jaime


-----Mensaje original-----
De: Michael Kay [mailto:mike(_at_)saxonica(_dot_)com]
Enviado el: Miércoles, 04 de Mayo de 2005 17:27
Para: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Asunto: RE: [xsl] How can I get context node in this complex expresion?
(current( ) didn't work)


Can't be done in a single XPath 1.0 expression - you need to build up the
result of the XPath expression in a series of variables declared at the XSLT
level.

In XPath 2.0 you use the "for" expression to bind variables at any level of
nesting, for example,

<xsl:apply-templates 
   select="ROW[for $x in COB_ID return $x =
$cob_rowset[CXC_CAD_ID=key('cad_key_ori', 
   $cob_rowset[COB_ID = $x]/CXC_CAD_ID)/CAD_REL_ID]/COB_ID]">

I'm assuming a ROW has only one COB_ID, otherwise these aren't equivalent. 

Michael Kay
http://www.saxonica.com/



-----Original Message-----
From: Jaime Stuardo [mailto:jstuardo(_at_)security(_dot_)cl] 
Sent: 04 May 2005 22:10
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] How can I get context node in this complex 
expresion? (current( ) didn't work)

Hi all...

This is the real case I have:

<xsl:apply-templates 
select="ROW[COB_ID=$cob_rowset[CXC_CAD_ID=key('cad_key_ori', 
$cob_rowset[COB_ID = 2]/CXC_CAD_ID)/CAD_REL_ID]/COB_ID]">

where:
      $cob_rowset : a nodeset that I assign previously. It is 
correctly assigned.
      'cad_key_ori' a key that is correctly defined as well.

That expresion works the way I want (showing some records 
according to the predicate). But that is a particular case. 
The general case is replacing the '2' above for the node 
COB_ID whose parent is ROW. For instance, I tried:

<xsl:apply-templates 
select="ROW[COB_ID=$cob_rowset[CXC_CAD_ID=key('cad_key_ori', 
$cob_rowset[COB_ID = 
current()/COB_ID]/CXC_CAD_ID)/CAD_REL_ID]/COB_ID]">

The call to current() didn't work (it didn't show anything 
and I know that 'COB_ID=2' is present in ROW nodeset). I 
think it is because current() is pointing to $cob_rowset context node.

Any help would be greatly appreciated.

Thanks
Jaime
      

--~------------------------------------------------------------------
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>
--~--