473,785 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT Template: Reusing with document()

Is it possible to use a template and then, in the same transformation,
reuse it for a call to document()?

I have a document that has a child. If necessary, I need to include
another document's (same structure) child. I'd like to reuse a
template but it doesn't seem to be working out for me.

<xsl:template match="/root">
<id><xsl:valu e-of select="name"/></id>
<children>
<xsl:apply-templates select="child"/>
<xsl:if test="string-length($additon al-id)>0">
<xsl:apply-templates select="documen t($additional-id)/
root"/>
</xsl:if>
</children>
</xsl:template>

<xsl:template match="child">
....
</xsl:template>

The code above will cause an infinite loop. I've tried passing the /
root/child element as a param to the child template, but that causes a
type mismatch error.

Any ideas? I'd hope that I wouldn't have to recreate the xsl:value-of
the elements of the child structure with a document()/root/.
Jun 27 '08 #1
2 1499
In article <d7************ *************** *******@b5g2000 pri.googlegroup s.com>,
dutone <du****@hotmail .comwrote:
>I have a document that has a child. If necessary, I need to include
another document's (same structure) child. I'd like to reuse a
template but it doesn't seem to be working out for me.

<xsl:templat e match="/root">
<id><xsl:valu e-of select="name"/></id>
<children>
<xsl:apply-templates select="child"/>
<xsl:if test="string-length($additon al-id)>0">
<xsl:apply-templates select="documen t($additional-id)/
root"/>
</xsl:if>
</children>
</xsl:template>

<xsl:templat e match="child">
....
</xsl:template>

The code above will cause an infinite loop.
You have a template that calls itself, and the recursive call
will be applied to the same element, so yes it will recurse indefinitely.

You could pass a parameter to the template that is the name of
the document to recurse on. Have a template for / that passes it
the second document's name, and have the recursive call pass in an
empty string (which you already check for).

-- Richard
--
:wq
Jun 27 '08 #2
Unless $additional-id changes each time around, the code you've shown
will indeed recurse endlessly, re-reading the same document(). There are
many possible solutions; which one makes sense depends on the details of
your problem.

For example: compute the variable from the source document so it's
different in each invocation. Or make it a template parameter and have
this recursion pass a different value down. Or use modes to distinguish
between processing the main input document and the one read via
document. Or ensure that the imported document doesn't have a /root
element and thus won't match this template and recurse again. Or...
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2712
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...
1
2570
by: Vince C. | last post by:
Hi all, I've created XML documents that are described with a schema. I'm using those documents to create web pages. All my web pages contain a fixed header and a variable document part. The header is the same in each page and is described in an XML document, "Head.xml". The document part, which is variable in content, is described in other XML files (e.g. "Document.xml", "Product.xml", "Register.xml").
20
6799
by: Bernd Fuhrmann | last post by:
Hi! I have some trouble with some simple stupid XSLT-stuff. My stylesheet: ------------- <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
1
8690
by: Victor | last post by:
Hi, this might sound silly but I cannot figure out how to incorporate some XML of employees into some XML of a company to give new XML containing them all. For example, this is the company now <COMPANY> <EMPLOYEE currentEmployee="true"> <NAME>Victor</NAME>
8
2164
by: Maciej Wegorkiewicz | last post by:
Hi, I have small experience in XSLT processing and I have a problem which I cannot solve. Can you look at it? I have an input file containing info about bank accounts like this: (...) <acc id="1"> <balance>100</balance>
3
3093
by: Ian Roddis | last post by:
Hello, I want to embed SQL type queries within an XML data record. The XML looks something like this: <DISPLAYPAGE> <FIELD NAME="SERVER" TYPE="DROPDOWN"> <OPTION>1<OPTION> <OPTION>2<OPTION> <OPTION>3<OPTION> </FIELD>
2
7403
by: Scamjunk | last post by:
I have been desperately looking for a treeview-type solution for my problem for the past three weeks and have been greatly unsuccessful. I am totally new to the world of XSLT and I *don't know* JavaScript. Still, I have managed to get something together, which I am putting across here. Any help (even pointing me to the place to look) is welcome. The problem I have is as follows:
8
15903
by: Hercules Dev. | last post by:
Hi all, I'm new in xslt and xpath, so my question might be simple but i'm learning. I have an XML document and need to transform it into another XML, I use xslt and it works, but there is a case that i don't know how to solve, I need to concat a string from multiple childs into a standard way, the following is an example of the source and the target XML.
3
9614
by: super.raddish | last post by:
Greetings, I am relatively new to, what I would call, advanced XSLT/XPath and I am after some advice from those in the know. I am attempting to figure out a mechanism within XSLT to compare the difference between two source documents and output node-sets which are "different" (changed or new) to new XML files using xsl:result-document To describe the problem I have provided some example data below along with my a portion of my current...
0
9646
marktang
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...
0
10346
Oralloy
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...
0
10157
jinu1996
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...
1
10096
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,...
0
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.