xsl-list
[Top] [All Lists]

RE: RE: Testing values from parent nodes

2004-05-26 02:59:12
FYI...  again, without seeing the context in which you are processing
'RR_group4' its tough to say if this is applicable, but you could also
use the following method that reduces the use of conditional logic
elements like xsl:if or xsl:choose[when][otherwise] by using the match
attribute of xsl:template to test for a particular value.  The following
tests for 3 possible values and outputs the associated text that
matches.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
  <xsl:apply-templates
select="RR/RR_row/RR_group1/RR_group2/RR_group3/RR_group4"/>
</xsl:template>
<xsl:template match="RR_group4[ancestor::RR_group2/type = 1]">
type 1
</xsl:template>
<xsl:template match="RR_group4[ancestor::RR_group2/type = 2]">
type 2
</xsl:template>
<xsl:template match="RR_group4[ancestor::RR_group2/type = 3]">
type 3
</xsl:template>
</xsl:stylesheet>

-----Original Message-----
From: M. David Peterson [mailto:m(_dot_)david(_at_)mdptws(_dot_)com]
Sent: Wednesday, May 26, 2004 3:42 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] RE: Testing values from parent nodes

Hey Neil,

I'm assuming that based on your sample code and the source XML that
you
are interested in the value of RR_group2/type as opposed to
RR_group1/type (which doesn?t exist)?  If so, and without seeing the
context in which you are processing RR_group4, heres a sample that
should help get you where you need to go...

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
  <xsl:apply-templates
select="RR/RR_row/RR_group1/RR_group2/RR_group3/RR_group4"/>
</xsl:template>
<xsl:template match="RR_group4">
  <xsl:if test="ancestor::RR_group2[type = '1']">
    hello world
  </xsl:if>
</xsl:template>
</xsl:stylesheet>

This will output "hello world" if the value of
ancestor::RR_group2/type
is equal to 1.  I treated 1 as a string by using the single quotes but
this would work just as well without them given that 1 can be treated
as
a string or a number by the processor.  You could also use <xsl:if
test="ancestor::RR_group2/type = '1'"> and get the same result.  The
difference between these two methods is show when they are used to
process the node and its children (as opposed to test for a value.)
"ancestor::RR_group2/type" puts 'type' into context where as
"ancestor::RR_group2[type]" puts 'RR_group2' into context if it has a
child with a local-name() of 'type'.

Let me know if this helps get you to where you need to be...

Best of luck!

<M:D/>

-----Original Message-----
From: SMITH Neil [mailto:neil(_dot_)smith(_at_)unifr(_dot_)ch]
Sent: Wednesday, May 26, 2004 3:07 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] RE: Testing values from parent nodes

<RR>
    <RR_row>
            <ind_no>81723</ind_no>
            <pos_acad_m_no>1</pos_acad_m_no>
            <pos_acad_lib>Emeritierte(r)
Professor(in)</pos_acad_lib>
            <et25_lng>2</et25_lng>
            <RR_group1>
                    <gr_no>330</gr_no>
                    <gr_nom>Analysis: Gruppe Kaup</gr_nom>
                    <RR_group2>
                            <type>1</type>
                            <type_lib>Publications</type_lib>
                            <RR_group3>
                                    <cle>15381</cle>
                                    <RR_group4>
                                            <ordre>10</ordre>
                                            <text>G. Bissig: Über
die Stabilität
separierbarer Blätterungen. Dissertation Fribourg, Juni 2002</text>
                                            <date_debut/>
                                            <date_fin/>
                                            <financement/>

<montant>0</montant>
                                    </RR_group4>
                            </RR_group3>
                    </RR_group2>


Here is a part of my XML file that I am parsing to HTML.
Here is my problem, I would like to test the value of
/RR/RR_Row/RR_group1[type=1]  while I am parsing the values of the
RR_group4 node (the output is not the same depending on the type).

I tried :
        <xsl:if
test="ancestor::RR/RR_row/RR_group1/RR_group2[type=1]">
            But that doesn't work (crashes XMLSPY...)
    <xsl:if test="/RR/RR_row/RR_group1/RR_group2[type=1]">
            Same same...


Could someone please help me as I have been stuck on this for a
couple
of
days now...

Thanks a lot
Best regards,
Neil.



Neil Smith
Analyste Programmeur
Université de Fribourg
Av. de l'Europe 20
CH - 1700 Fribourg
Tél. +41 26 300 7091



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



<Prev in Thread] Current Thread [Next in Thread>