xsl-list
[Top] [All Lists]

RE: [xsl] Connecting the Source and Destination fields

2007-08-29 03:44:31
Hi can you please explain me what exactly the below line is doing and how it
is working?

<xsl:for-each 
select="/root/connection[not(/root/connection/@destination = @source)]">

Waiting for your mail!

Thanks
Yaswanth Ravella
-----Original Message-----
From: Ronan Klyne [mailto:ronan(_dot_)klyne(_at_)groupbc(_dot_)com] 
Sent: Monday, August 20, 2007 1:40 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Connecting the Source and Destination fields

Ooops - A mistake in the XSL - here's the working one:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
<xsl:output method="html" indent="yes" encoding="ISO-8859-1"/>

<xsl:key name="source-conn" match="/root/connection" use="@source"/>

<xsl:template match="/root">
  <xsl:for-each
select="/root/connection[not(/root/connection/@destination = @source)]">
    <xsl:value-of select="@source"/>
    <xsl:call-template name="do-next">
      <xsl:with-param name="source" select="@source"/>
    </xsl:call-template>
    <xsl:text>
    </xsl:text>
  </xsl:for-each>
</xsl:template>

<xsl:template name="do-next">
  <xsl:param name="source"/>
  <xsl:variable name="conn" select="key('source-conn', $source)"/>
  <xsl:if test="$conn">
    <xsl:text> -&gt; </xsl:text>
    <xsl:value-of select="$conn/@destination"/>
    <xsl:call-template name="do-next">
      <xsl:with-param name="source" select="$conn/@destination"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>

        # r

Ronan Klyne wrote:
To me, keys seem to be the way forward here. Does the following
stylesheet make sense to you?

------- XSL:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
<xsl:output method="html" indent="yes" encoding="ISO-8859-1"/>

<xsl:key name="source-conn" match="/root/connection" use="@source"/>

<xsl:template match="/root">
  <xsl:for-each
select="/root/connection[not(/root/connection/@destination = @source)]">
    <xsl:value-of select="@source"/>
    <xsl:call-template name="do-next">
      <xsl:with-param name="source" select="@destination"/>
    </xsl:call-template>
    <xsl:text>
    </xsl:text>
  </xsl:for-each>
</xsl:template>

<xsl:template name="do-next">
  <xsl:param name="source"/>
  <xsl:variable name="conn" select="key('source-conn', $source)"/>
  <xsl:if test="$conn">
    <xsl:text> -&gt; </xsl:text>
    <xsl:value-of select="$conn/@source"/>
    <xsl:call-template name="do-next">
      <xsl:with-param name="source" select="$conn/@destination"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>

------- INPUT:

<root>
<connection destination="event.3" source="event.0"/>
<connection destination="event.1" source="event.2"/>
<connection destination="event.2" source="event.3"/>
<connection destination="event.4" source="event.1"/>
</root>

------- END

      # r

Yaswanth wrote:
Hi Andrew, 
Thanks for the reply
But I have some issues ! 

What if I have some ting like this ? 

<connection destination="event.3" source="event.0"/> 
<connection destination="event.1" source="event.2"/> 
<connection destination="event.2" source="event.3"/> 
<connection destination="event.4" source="event.1"/>

By using 

<xsl:sort select="@source"/>

For understanding my input will change to  :

<connection destination="event.3" source="event.0"/> 
<connection destination="event.4" source="event.1"/>
<connection destination="event.1" source="event.2"/> 
<connection destination="event.2" source="event.3"/> 

My output will be 
     event.0 -> event.3 -> event.4 -> event.1 -> event.2


But I am expecting 

     event.0 -> event.3 -> event.2 -> event.1 -> event.4
     

Regards,
Yaswanth

-----Original Message-----

From: Andrew Welch [mailto:andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com] 
Sent: Monday, August 20, 2007 1:04 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Connecting the Source and Destination fields

On 8/20/07, Yaswanth <yaswanth(_dot_)mtrx(_at_)gmail(_dot_)com> wrote:
Hi All,

I am trying to arrange the chain of event connections by mapping the
Source
and Destination of each Connection.

When my XML file is something like this:

<connection destination="event.1"source="event.0"/>
<connection destination="event.2" source="event.1"/>
<connection destination="event.3" source="event.2"/>
<connection destination="event.4" source="event.3"/>

// Ordered
// Please note that The Destination Value of any node is equal to the
Source
value of the next Node

Here I am taking the 'source' value from the first 'connection' and by
keep
on appending the 'destination' value of all the 'connection's I get the
Output as:


event.0 -> event.1 -> event.2 -> event.3 -> event.4

Problem:

Now my XML input file is changed to some thing like this :

<connection destination="event.1" source="event.0"/>
<connection destination="event.3" source="event.2"/>
<connection destination="event.2" source="event.1"/>
<connection destination="event.4" source="event.3"/>

// Unordered
// Please note that The Destination Value of any node is not always
equal
to
the Source value of the next Node

If I process this XML file in the same way I did the earlier one I will
get
output as:

event.0 -> event.1 -> event.3 -> event.2 -> event.4

Here event.1's destination is event.2 only but in the Output I am having
event.3 as the destination.
event.2's destination is event.3 only but in the Output I am having
event.4
as the destination.
event.3's destination is event.4 only but in the Output I am having
event.2
as the destination.

I know this is happening because of the Logic I used in arranging these
things..

Can I get some push on how to arrange these things in Order?!
Sort them :

<xsl:sort select="@source"/>

?





-- 
Ronan Klyne
Business Collaborator Developer
Tel: +44 (0)870 163 2555
ronan(_dot_)klyne(_at_)groupbc(_dot_)com
www.groupbc.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>
--~--

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