I have a document about 4 levels deep and in my XSLT I want to generate
a unique string ID for each basic element based on its path through the
hierarchy.
If I use recursion, I am continually accessing the root element ID, here
is a typical call:
<xsl:variable name="fullPath"
select="concat( 'p',../../../@id,'_c',../../@id,'_r',../@id,'_s',$slave ID)
"/>
I *could* do this by nesting call-templates and passing the current id
as a parameter. Is this likely to be more or less efficient?
e.g. starting xml:
<castle id="0>
<level id="2">
<room id="2"/>
<room id="3"/>
<room id="4"/>
</level>
<level id="3">
<room id="2"/>
<room id="3"/>
<room id="4"/>
</level>
</castle>
so heres an xslt:
<xsl:template match="castle">
<xsl:fullPath select="concat( 'c',@id)"/>
<thisCastle uid="{$fullPath }"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="level">
<xsl:fullPath select="concat( 'c',../@id,'_l',@id)"/>
<thisLevel uid="{$fullPath }"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="room">
<xsl:fullPath select="concat( 'c',../../@id,'_l',../@id,'_r',@id)"/>
<thisRoom uid="{$fullPath }"/>
<xsl:apply-templates/>
</xsl:template>
I'm guessing this is very inefficient, accessing the castle ID for each
room. is there a better way? I could generate an ID, but would the ID
reflect the data path it took to get to a particular room?
cheers
shaun 3 2696
shaun roe wrote: I'm guessing this is very inefficient, accessing the castle ID for each room. is there a better way?
Well if you know that is the root element then a global variable
<xsl:variable name="rootId" select="/castle/@id" />
is all you need, then in your expressions you can use
$rootId
--
Martin Honnen http://JavaScript.FAQTs.com/
In article <43************ ***********@new sread4.arcor-online.net>,
Martin Honnen <ma*******@yaho o.de> wrote: shaun roe wrote:
I'm guessing this is very inefficient, accessing the castle ID for each room. is there a better way?
Well if you know that is the root element then a global variable <xsl:variable name="rootId" select="/castle/@id" /> is all you need, then in your expressions you can use $rootId
True, but accessing the root element multiple times is only the worst
symptom of my philosophy... each 'parent' Id gets recalled by each of
its children, each grandparent by both the children and grandchildren
etc. Maybe this is equally efficient as the nested template-call,
(passing the id as a parameter to children) if this information is
somehow cached... I dont know.
The following transformation implements all your requirements:
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="ye s" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@ *">
<xsl:copy>
<xsl:attribut e name="globalId" >id<xsl:text/>
<xsl:number count="*" level="multiple "/>
</xsl:attribute>
<xsl:apply-templates select="node()| @*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
When applied on the source xml provided in your post, the result is:
<castle globalId="id1" id="0">
<level globalId="id1.1 " id="2">
<room globalId="id1.1 .1" id="2"/>
<room globalId="id1.1 .2" id="3"/>
<room globalId="id1.1 .3" id="4"/>
</level>
<level globalId="id1.2 " id="3">
<room globalId="id1.2 .1" id="2"/>
<room globalId="id1.2 .2" id="3"/>
<room globalId="id1.2 .3" id="4"/>
</level>
</castle>
Cheers,
Dimitre Novatchev
"shaun roe" <sh*******@wana doo.fr> wrote in message
news:sh******** *************** ******@news-reader.wanadoop ortails.com... I have a document about 4 levels deep and in my XSLT I want to generate a unique string ID for each basic element based on its path through the hierarchy.
If I use recursion, I am continually accessing the root element ID, here is a typical call:
<xsl:variable name="fullPath" select="concat( 'p',../../../@id,'_c',../../@id,'_r',../@id,'_s',$slave ID) "/>
I *could* do this by nesting call-templates and passing the current id as a parameter. Is this likely to be more or less efficient?
e.g. starting xml:
<castle id="0> <level id="2"> <room id="2"/> <room id="3"/> <room id="4"/> </level> <level id="3"> <room id="2"/> <room id="3"/> <room id="4"/> </level> </castle>
so heres an xslt:
<xsl:template match="castle"> <xsl:fullPath select="concat( 'c',@id)"/> <thisCastle uid="{$fullPath }"/> <xsl:apply-templates/> </xsl:template>
<xsl:template match="level"> <xsl:fullPath select="concat( 'c',../@id,'_l',@id)"/> <thisLevel uid="{$fullPath }"/> <xsl:apply-templates/> </xsl:template>
<xsl:template match="room"> <xsl:fullPath select="concat( 'c',../../@id,'_l',../@id,'_r',@id)"/> <thisRoom uid="{$fullPath }"/> <xsl:apply-templates/> </xsl:template>
I'm guessing this is very inefficient, accessing the castle ID for each room. is there a better way? I could generate an ID, but would the ID reflect the data path it took to get to a particular room?
cheers
shaun This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sergio del Amo |
last post by:
Hi,
I use the xslt functions provided by php. I am running in my computer
the package xampp(www.apachefriends.org) which includes php/apache/mysql
.. In this package the php includes the sablotron extension responsible
for the xslt functions. The problem i have is that the obtained
transformation is not the waited one. I try to proccess the same XML
file with XSL file with a program called XMLspy and i obtained the
desire and waited...
|
by: Leo Kirch |
last post by:
Hello XSLT gurus,
i've got a rather difficult problem. Some explanations first.
theres a signal oriented xml-file - the graphical represantation looks
like:
| startsignal (signal00)
\ /
---------------------------------------------------------
|
by: Jens Mueller |
last post by:
Hi there,
this is a Java-XML Question, so I am not sure whether this is the
right place, haven't found anything better ....
I try to convert a Java object to XML via SAX and let the FOP
Transformer convert that via XSLT to valid XSL-FO. So I define a
SAXReader which fires the SAX Events for the Java Object. This works
fine and the Transformation to PDF is ok.
However, I have one object which contains an XHTML String and the tags
|
by: Vincent Lefevre |
last post by:
Under Linux, I currently use xsltproc (libxslt), but it is awfully
slow and takes a lot of memory (e.g. more than 100 MB) when using
many XML files with a large DTD (e.g. DocBook): With my DTD (based
on DocBook + MathML), each time a XML file is read, xsltproc spends
1 second parsing its DTD, and I end up losing a factor 100 due to
that.
I now use fake DTDs (by providing a special catalog), which just
define the entities I need, so that...
|
by: Chris Young |
last post by:
Operating Ubunutu Linux 5.04 on iMac 333mhz
Python 2.4.1 in IDLE 1.1.1
In trying to create a interactive drawing framework in Python I came across
the idea of binding attributes of one object to attributes of another.
The way it works is when obj1.attr1 is set obj2.attr2 should have it's
__setattr__ method called as well. But it ends up giving me a recursion error.
The attribute synchronization is shown below:
| |
by: Mike Grass |
last post by:
Hi,
I have an XML file similar to the following:
<!-- snippet -->
<selector key='USER/id' value='type1'/>
<selector key='USER/id' value='type2'/>
<selector key='USER/id' value='type3'/>
<options>
<USER>
<NAME>Bob</NAME>
|
by: dwergkees |
last post by:
Hi,
Got a litte problem here. I'm trying to create a XSLT file that will do
a transformation from WordML format (MS Word XML format, see
http://rep.oio.dk/Microsoft.com/officeschemas/welcome.htm) to a
reasonably clean (X)HTML format.
(The reason being that, combined with some PHP scripting it should be
possible to store the embedded images, which is pretty neat).
|
by: notnorwegian |
last post by:
when using recursion should one use a return statement or not?
there is a difference obv since with a return statement it will
ultimately return a value if not recursing forever.
but is there a guideline for this or it just taste or is it
considering good style or pythonic to always have a returnvalue?
|
by: z1 |
last post by:
hi-
i am fooling around with soap and weather templates.
for some reason either this if or select is failing.
i am very new to xml and found this code at another site.
i can show you the xml and then the xslt sample code that is not matching.
please look and if it jumps right off the page give me a tip on why it didnt
select the data.
i think for most xslt people this will be easy. i want the if to work if it
is null because
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |