xsl-list
[Top] [All Lists]

Re: joining nodes

2006-02-16 08:56:59
should be transformed to the (text) output:

n1
 v11
 >v21
n2
> v21
 >v22

because n1 is associated to v11 and v21 and n2 is associated to v21 and
v22 in <aaa/> and <bbb/> respectively.

Did you mean

n1
 v11
 v21
n2
v12 **
 v22

because n1 is associated to v11 and v21 and n2 is associated to v12 and
v22 in <aaa/> and <bbb/> respectively.
See if there was a typo in your n2 values.

Any way.. David Suggested...

<xsl:for-each select="aaa/name">
<xsl:value-of select="."/>
  <xsl:value-of select="../value1"/>
  <xsl:value-of select="/join1/bbb/a[name=current()]/value2
</xsl:for-each>

Will this work if he had

<ccc>
 <a>
   <name>n1</name>
   <value2>v31</value2>
 </a>
 <a>
   <name>n2</name>
   <value2>v32</value2>
 </a>
</ccc>

and <ddd> and .... <nnn>??

I think it is better to group them by Name and then Print their values.


<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:key match="//a" name="names" use="name/text()"/>
<xsl:template match="join1">

<xsl:for-each select="//a[generate-id(.) = generate-id(key('names',name/text())[1])]">
         <xsl:variable name="name" select="name/text()"/>
    <xsl:value-of select = "$name"/>
                        <br/>

  <xsl:for-each select="key('names',$name)">
    <xsl:value-of select = "*[contains(name(),'value')]/text()"/>
<br/>
  </xsl:for-each>

<hr/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

The above is in XSLT1 you could use more advanced grouping techniques of XSLT2 to do the same.

Try if this works.
Vasu


From: David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] joining nodes
Date: Thu, 16 Feb 2006 15:27:04 GMT

first one is just something like
<xsl:for-each select="aaa/name">
: <xsl:value-of select="."/>
:   <xsl:value-of select="../value1"/>
:   <xsl:value-of select="/join1/bbb/a[name=current()]/value2
</xsl:for-each>

second one is something like

<xsl:for-each select="aaa/ident">
: <xsl:value-of select="."/>
  <xsl:text> </xsl:text>
  <xsl:value-of select="/join2/bbb/a[ident=current()]/subject
</xsl:for-each>


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


_________________________________________________________________
The new MSN Search Toolbar now includes Desktop search! http://toolbar.msn.co.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>
--~--



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