Hi,
I am an XSLT newbie. I need to solve something which I will express in
pseudo-code.
function f1()
{
xmltree = <emptydom>
addnamevaluepai r(xmltree, "size","100 ")
addnamevaluepai r(xmltree, "color","bl ue")
}
function addnamevaluepai r(dom, name, value)
{
//add element : <attrib>
// <name>....</name>
// <value>...</value>
// </attrib>
//to the dom and return it
return xmldom
}
What would the equivalent be in XSLT?
Thanks in advance,
Prashanth 6 1517
Prashanth Ellina wrote: I am an XSLT newbie. I need to solve something which I will express in pseudo-code.
function f1() { xmltree = <emptydom> addnamevaluepai r(xmltree, "size","100 ") addnamevaluepai r(xmltree, "color","bl ue") }
function addnamevaluepai r(dom, name, value) { //add element : <attrib> // <name>....</name> // <value>...</value> // </attrib> //to the dom and return it return xmldom }
What would the equivalent be in XSLT?
<xsl:template match="/">
<root>
<xsl:call-template name="addnameva luepair">
<xsl:with-param name="name" select="'size'" />
<xsl:with-param name="value" select="100" />
</xsl:call-template>
<xsl:call-template name="addnameva luepair">
<xsl:with-param name="name" select="'color' " />
<xsl:with-param name="value" select="'blue'" />
</xsl:call-template>
</root>
</xsl:template>
<xsl:template name="addnameva luepair">
<xsl:param name="name" />
<xsl:param name="value" />
<attrib>
<name><xsl:valu e-of select="$name" /></name>
<value><xsl:val ue-of select="$value" /></value>
</attrib>
</xsl:template>
--
Martin Honnen http://JavaScript.FAQTs.com/
Hi,
What should I do if I want to add another attrib element between the
two already created. Can I treat the generated xml as a dom tree and do
an AddAfterNode() or something?
Thanks,
Prashanth
Prashanth Ellina wrote: What should I do if I want to add another attrib element between the two already created. Can I treat the generated xml as a dom tree and do an AddAfterNode() or something?
No, XSLT is template based, while an input tree (in the sense of the
XPath data model which is different from the DOM model) is transformed
to an ouput tree there are no methods or functions inserting or adding
nodes at a particular node. The whole approach is different, templates
are processed and their contents is instantiated as part of the result
tree being formed.
It does not help to think in DOM terms (and the W3C DOM does not have a
AddAfterNode method at all), if you want to learn XSLT then you would
better look at tutorials and introductions and look at example solutions.
If you want help here implementing an XSLT transformation then it is
usually a good idea to show us your input XML data and the desired (XML
or HTML or text) output.
--
Martin Honnen http://JavaScript.FAQTs.com/
Hi,
I find the XSLT programming model very alien and un-intuitive. The most
restrictive thing is that I cannot maintain state across
function/template calls.
This is what I am looking to do
Input document:
<booksinformati on>
<book>
<title>book title 1</title>
<author>Krame r</author>
</book>
<book>
<title>book title 2</title>
<author>Terry </author>
</book>
<book>
<title>book title 3</title>
<author>Terry </author>
</book>
</booksinformatio n>
Output document:
<booksinformati on>
<bookdata>
<book author='1'>
<title>book title 1</title>
</book>
<book author='2'>
<title>book title 2</title>
</book>
<book author='2'>
<title>book title 3</title>
</book>
</bookdata>
<authordata>
<author id="1" name="Kramer"/>
<author id="2" name="Terry"/>
</authordata>
</booksinformatio n>
The output document avoid duplication of data by maintaining a subtree
for authors into which the bookdata can point.
Thank you,
Prashanth
Tempore 15:35:06, die Monday 01 August 2005 AD, hinc in foro {comp.text.xml} scripsit Prashanth Ellina <pr************ *@gmail.com>: I find the XSLT programming model very alien and un-intuitive.
You'll be used to it in no time;) It's just another way of thinking.
This is what I am looking to do ...
This a grouping problem, here's a solution with the Muenchian grouping technique, one of the most alien things for beginners:-)
<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="author" match="author" use="."/>
<xsl:variable name="allAuthor s" select="//author[generate-id()=generate-id(key('author' ,.)[1])]"/>
<xsl:template match="booksinf ormation">
<xsl:copy>
<bookdata>
<xsl:apply-templates/>
</bookdata>
<authordata>
<xsl:for-each select="$allAut hors">
<author id="{position() }" name="{.}"/>
</xsl:for-each>
</authordata>
</xsl:copy>
</xsl:template>
<xsl:template match="book">
<xsl:variable name="author" select="author"/>
<xsl:copy>
<xsl:attribut e name="author">
<xsl:for-each select="$allAut hors">
<xsl:if test=". = $author"><xsl:v alue-of select="positio n()"/></xsl:if>
</xsl:for-each>
</xsl:attribute>
<xsl:copy-of select="title"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
regards,
--
Joris Gillis ( http://users.telenet.be/root-jg/me.html)
Deserta faciunt et innovationem appelant
Hi,
That looks great. I will "muench" that. Thanks a lot.
Prashanth
Joris Gillis wrote: Tempore 15:35:06, die Monday 01 August 2005 AD, hinc in foro {comp.text.xml} scripsit Prashanth Ellina <pr************ *@gmail.com>:
I find the XSLT programming model very alien and un-intuitive. You'll be used to it in no time;) It's just another way of thinking.
This is what I am looking to do ...
This a grouping problem, here's a solution with the Muenchian grouping technique, one of the most alien things for beginners:-)
<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/>
<xsl:key name="author" match="author" use="."/> <xsl:variable name="allAuthor s" select="//author[generate-id()=generate-id(key('author' ,.)[1])]"/>
<xsl:template match="booksinf ormation"> <xsl:copy> <bookdata> <xsl:apply-templates/> </bookdata> <authordata> <xsl:for-each select="$allAut hors"> <author id="{position() }" name="{.}"/> </xsl:for-each> </authordata> </xsl:copy> </xsl:template>
<xsl:template match="book"> <xsl:variable name="author" select="author"/> <xsl:copy> <xsl:attribut e name="author"> <xsl:for-each select="$allAut hors"> <xsl:if test=". = $author"><xsl:v alue-of select="positio n()"/></xsl:if> </xsl:for-each> </xsl:attribute> <xsl:copy-of select="title"/> </xsl:copy> </xsl:template>
</xsl:stylesheet>
regards, -- Joris Gillis (http://users.telenet.be/root-jg/me.html) Deserta faciunt et innovationem appelant 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: Don Garrett |
last post by:
I have an XML document at the root of a directory tree that contains
relative URIs to resources in a directory tree.
During XSLT processing, these URI's can be used without any problems
to access the various documents in the tree. However, when generating
HTML output, the output <a href=""> tags need to be adjusted for the
location of the document that is displaying them.
I need to use relative URLs, since the documents need to be...
|
by: titanandrews |
last post by:
Hi,
I have ran into a situation that I think should be possible, but I am
fairly new to XSLT so maybe not.
Suppose I have the following document
<ROOT>
<FOO name="A">
<CHILD name="B"/>
</FOO>
|
by: Jack Fox |
last post by:
I've never had the need to work with XML, but I believe I now have an
appropriate application. I have time-series data in objects organized as a
tree that I want an ASP.NET program to write out to web pages formatted as a
matrix. It is not a simple matrix, since the number of row heading cells can
vary, but the data cells must be aligned by date (so the heading cells will
not be uniformly sized).
example of typical rows:
3 heading...
|
by: Mike P |
last post by:
I am quite new to XML and XSLT, and I know you can apply XSLT to XML to
display data in an XML file according to the XSLT file, but is it
possible to apply an XSLT file to page/s of HTML, so that you aren't
just limited to your XML data, but can transform a whole web page?
Any assistance would be really appreciated.
Cheers,
| |
by: RJN |
last post by:
Hi
Can XSLT be applied for transforming .txt files or are they applicable
only for xml to xml transformation.
Currently all the clients send file to a server in one particular
format. The format of the file which the server accepts is going to
change. So we need to build an intermediate system which will do the
transformation from the old format to the new format. Can I use XSLT for
doing this? Is XSLT applicable only when xml to xml...
|
by: sebastian.langer |
last post by:
Hi!
Certainly somebody had my problem before and could give me just some
hints, how to solve it:
I have an xml file, which contains scientific data in a tree form. The
data should be changed in a JSR168-Portlet and in a Python-Environment
as well, so I want them to be parsed by an xslt to html which then
could be shown in a web browser.
|
by: yinglcs |
last post by:
Hi,
I have a newbie XSLT question. I have the following xml, and I would
like to
find out the children of feature element in each 'features' element.
i.e. for each <featuresI would like to look up what each feature
depends on and gerenate a text file. For example, in the following
file, I would like to find out feature A depends on A1 and A2 and
feature B depends on B1 and B2. And write that to a text file.
|
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: 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: 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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
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...
| |