xsl-list
[Top] [All Lists]

Re: dynamic node access

2005-02-21 08:06:37
Oh thanks it worked !

Theres one more problem I have. The output of my present transformation is of the form

------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<Top>
<PrimeConcept id="10180">
 <PrimeName>Car</PrimeName>
 <SubConcepts>
     <SubConcept id="10298" name="Toyota"/>
 </SubConcepts>
</PrimeConcept>
</Top>
------------------------------
However I want the output in the form

<PrimeConcept id='10180'>Car</PrimeConcept>
<SubConcepts>
 <SubConcept id='10298'>Toyota</SubConcept>
</SubConcepts>

I am not sure how you can create the element <SubConcepts> from within the <PrimeConcept> template match. My present code is

-------------------------------------
<xsl:template match="/">
   <Top>
<PrimeConcept><xsl:apply-templates select="Top/TopNode" mode="top"/></PrimeConcept>
   </Top>
</xsl:template>

<xsl:template match="TopNode" mode="top">
    <xsl:if test="@name = $prime"> <!--e.g. resolves to 'Car'>
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> <xsl:element name="PrimeName"><xsl:value-of select="@name"/></xsl:element><!-- e.g. Car--> <xsl:for-each select="following-sibling::TopNode[(_at_)name = $constraint] | preceding-sibling::TopNode[(_at_)name=$constraint]"> <!--e.g. resolves to 'Toyota'> <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>

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

So how can I create the element <SubConcepts> below <Top> and not <PrimeConcept> ?

Thanks
Rahil


David Carlisle wrote:

You hardly posted enough information to guess an answer, but

<xsl:if test="following-sibling::TopNode[(_at_)name = $constraint]">
xsl:if is just a boolean test it doesn't change the current node.
If you want to change the current node to that node (if it is there)
change that to

<xsl:for-each test="following-sibling::TopNode[(_at_)name = $constraint]">
David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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