xsl-list
[Top] [All Lists]

problem retrieving node attribute value

2005-02-18 10:11:29
Hi

I'm reposting as I've made a few changes to my code.

The <xsl:template> block below is the code I've written to find a concept 
'Pain' and then its child/grandchild 'Headache' from an xml file.

However the result aint accurate (I've explained the problems after the code).


-------------------------------------
<xsl:template match="DEFCONCEPT" mode="top">
         <xsl:if test="@name = $prime"> <!--e.g. resolves to 'Pain'>
                <xsl:attribute name="id"><xsl:value-of 
select="@id"/></xsl:attribute>
                <xsl:element name="PrimeName"><xsl:value-of 
select="@name"/></xsl:element><!-- e.g. Pain-->
<xsl:if test="following-sibling::DEFCONCEPT[(_at_)name = $constraint] | preceding-sibling::DEFCONCEPT[(_at_)name=$constraint]"> <!--e.g. resolves to 'Headache'>
                        <xsl:element name="SubConcepts">
                                <xsl:element name="SubConcept">
                                        <xsl:attribute name="id"><xsl:value-of 
select="@id"/></xsl:attribute>
                                        <xsl:attribute name="name"><xsl:value-of 
select="@name"/></xsl:attribute>
                                </xsl:element>
                        </xsl:element>
                </xsl:if>
        </xsl:if> 
</xsl:template>

-----------------------------------

The resulting output is such

------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<Top>
<PrimeConcept id="10180">
  <PrimeName>Pain</PrimeName>
  <SubConcepts>
      <SubConcept id="10180" name="Pain"/> <!-- it should really be 
'Headache'-->
  </SubConcepts>
</PrimeConcept>
</Top>
------------------------------
I have two problems though. First, my <SubConcept> element tag displays 'Pain' and '10180' instead of 'Headache' and '10279'. Is that because the control still remains at the 'Pain' element? How do I resolve this issue?

Second, the actual output I'd like is
<PrimeConcept></PrimeConcept>
<SubConcepts>
  <SubConcept></SubConcept>
</SubConcepts>

but I'm not sure how to create a top-level node <SubConcepts> from within the <PrimeConcept> if clause.

Could someone please help  me out with this?

Thank you
Rahil




--~------------------------------------------------------------------
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>
  • problem retrieving node attribute value, RQamar <=