xsl-list
[Top] [All Lists]

Re: Outputing the same value-of for different nodes

2006-02-22 09:56:18
Mike Kay and the other transformation engine developers might be able to
answer to provide some details about optimization. However, I suspect the
only way you'll find the best performance is to set up a number of different
solutions and test them with the engine of your choice.

Jay Bryant
Bryant Communication Services

----- Original Message ----- 
From: "Liron" <magilam(_at_)netvision(_dot_)net(_dot_)il>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Wednesday, February 22, 2006 10:47 AM
Subject: Re: [xsl] Outputing the same value-of for different nodes


Thank you for your reply,

I realize that this solution is quite simple but I was more curious about
the performance. If I apply the same template twice (or more) will any
good
engine optimize that some how or will it select "son" twice (or more)?

Thank you
Liron

----- Original Message ----- 
From: "Jay Bryant" <jay(_at_)bryantcs(_dot_)com>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Wednesday, February 22, 2006 5:39 PM
Subject: Re: [xsl] Outputing the same value-of for different nodes


If you use templates rather than for-each, this is a fairly natural
operation for XSLT. Then you just need to apply the son template twice,
thus:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

 <xsl:output method="xml" indent="yes"/>

 <xsl:template match="tree">
   <xsl:copy>
     <first>
       <xsl:apply-templates/>
     </first>
     <second>
       <xsl:apply-templates/>
     </second>
   </xsl:copy>
 </xsl:template>

 <xsl:template match="son">
   <xsl:copy>
     <xsl:apply-templates/>
   </xsl:copy>
 </xsl:template>

 <xsl:template match="value">
   <xsl:copy>
     <xsl:value-of select="."/><position><xsl:value-of
select="count(preceding::value) + 1"/></position>
   </xsl:copy>
 </xsl:template>

</xsl:stylesheet>

Jay Bryant
Bryant Communication Services



----- Original Message ----- 
From: "Liron" <magilam(_at_)netvision(_dot_)net(_dot_)il>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Wednesday, February 22, 2006 10:19 AM
Subject: [xsl] Outputing the same value-of for different nodes


Hello,

I wanted to ask how to output the same value on different nodes without
effecting performance. Here's an example:

original xml file:

<tree>
   <son><value>something1</value></son>
   <son><value>something2</value></son>
   <son><value>something3</value></son>
</tree>

Lets assume I want to output something like this:

<tree>
   <first>
       <son><value>something1><position>1</position></value></son>
       <son><value>something2><position>2</position></value></son>
       <son><value>something3><position>3</position></value></son>
   </first>
   <second>
       <son><value>something1><position>1</position></value></son>
       <son><value>something2><position>2</position></value></son>
       <son><value>something3><position>3</position></value></son>
   </second>
</tree>

This is just an example so please don't question the need for such an
output
;)

In my xslt I'd probably use a xsl:for-each select="/tree/son" and then
output the "value" node and "position()" under the "first" node but
would
I
have to write a
"xsl:for-each" again only output it for the "second" node or there's
some
way of outputing the same value, lets say "position()", under different
output nodes?

Thank you
Liron


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



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