473,670 Members | 2,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simple xslt problem/question

Hi, i have a real simple xslt problem but i just cant figure out how
to do it by looking at various examples on the net. i have a xml
document and in it are some elements with a "result" tag name. i want
to use xslt to reproduce exactly the same xml document except with an
attribute called "id" added to those elements with a "result" tag name.
can this be done? if so any helps greatly appreciated

Jul 20 '05 #1
6 1809


ch*****@gmail.c om wrote:
Hi, i have a real simple xslt problem but i just cant figure out how
to do it by looking at various examples on the net. i have a xml
document and in it are some elements with a "result" tag name. i want
to use xslt to reproduce exactly the same xml document except with an
attribute called "id" added to those elements with a "result" tag name.
can this be done?


Where would the id attribute value come from?
Please post a short example XML and the desired result XML.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
the id attrribute would be generated by using the "generate-id()" xslt
function to give each result a unique identifier

part of the xml doc with some sample results is provided below ...

<hl7:ControlAct Process moodCode='RQO'>
<hl7:code code='QUQI_TE00 0002'/>
<hl7:subject>
<hl7:act moodCode='EVN'>
<hl7:result>Wei ght 2001-01-12 11.2</hl7:result>
<hl7:result>Wei ght 2001-01-13 11.2</hl7:result>
</hl7:act>
</hl7:subject>
<hl7:queryAck >
<hl7:queryRespo nseCode code='OK'/>
<hl7:resultTota lQuantity value='2'/>
</hl7:queryAck>
</hl7:ControlActP rocess>

after using xslt to perform the transformations , the same xml doc
would be produced except the result tags would now look like

<hl7:result id='d012' >Weight 2001-01-12 11.2</hl7:result>
<hl7:result id='d013' >Weight 2001-01-13 11.2</hl7:result>

where "d012" and "d013" are generated through the "generate-id()"
function.

Jul 20 '05 #3


ch*****@gmail.c om wrote:
the id attrribute would be generated by using the "generate-id()" xslt
function to give each result a unique identifier

part of the xml doc with some sample results is provided below ...

<hl7:ControlAct Process moodCode='RQO'>
<hl7:code code='QUQI_TE00 0002'/>
<hl7:subject>
<hl7:act moodCode='EVN'>
<hl7:result>Wei ght 2001-01-12 11.2</hl7:result>
<hl7:result>Wei ght 2001-01-13 11.2</hl7:result>
</hl7:act>
</hl7:subject>
<hl7:queryAck >
<hl7:queryRespo nseCode code='OK'/>
<hl7:resultTota lQuantity value='2'/>
</hl7:queryAck>
</hl7:ControlActP rocess>

after using xslt to perform the transformations , the same xml doc
would be produced except the result tags would now look like

<hl7:result id='d012' >Weight 2001-01-12 11.2</hl7:result>
<hl7:result id='d013' >Weight 2001-01-13 11.2</hl7:result>

where "d012" and "d013" are generated through the "generate-id()"
function.


Then start with the identity transformation e.g.

<xsl:styleshe et
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>

then add a template to change those result elements as needed

<xsl:template xmlns:hl7="putp ropernamespaceU RIhere"
match="h17:resu lt">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:attribut e name="id"><xsl: value-of select="generat e-id()"
/></xsl:attribute>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #4
that stylesheet works perfectly, much thanks for the speedy reply and
solution

Jul 20 '05 #5
oh just one more thing with that stylesheet, is there anyway to return
the attributes with only single inverted commas around their values,
i.e a " ' " as opposed to the double inverted commas or will the
stylesheet only produce output with attribute values surrounded by
double quotation marks? thanks

Jul 20 '05 #6


ch*****@gmail.c om wrote:
oh just one more thing with that stylesheet, is there anyway to return
the attributes with only single inverted commas around their values,
i.e a " ' " as opposed to the double inverted commas or will the
stylesheet only produce output with attribute values surrounded by
double quotation marks?


The quoting character is a serialization issue which can't be controlled
from the stylesheet.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #7

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

Similar topics

1
5577
by: Lisa | last post by:
I need to apply the HTML formatting tags and the French accented characters in a XML document. The XML is generated from a database that has HTML tags and French accented characters in the records. I have specified <xsl:output method="html"/> and encoding="iso-8859-1". When I apply the xsl:value-of and set the disable-output-escaping to "yes", the HTML formatting tags are displayed correctly, but the French accented characters are...
1
1418
by: Howard | last post by:
Hi, I am using a very simple xslt file to get info from an xml document. The problem seems to me to be that the xml doc uses a namespace, and I don't know how to set up my xslt to recognize it correctly. If I remove the namespace specification from the xml, I can query the node I want perfectly. But with that namespace in there, it fails. Can someone help? Here's a simpilified version of the xml document, with that namespace stuff:
4
2324
by: el_bandido | last post by:
Hello, I've tried the FAQ and some minutes in googl'ing but was not happy with what I got. Basically I'd like to get a _simple_ example on how I could create a web based (portable across all platforms and applications) form for a simple web application using XML technologies. I would like to have something like follows: An XML DB containing that looks roughly like follows:
4
1975
by: Gauthier | last post by:
Hi, I've a simple issue with the use of extension objects. I'm trying to call a text formating method from an object that I add to my arguments collection, this method take an input string and output the formatted string. So far everything process correctly (the method is called without any issue) but my problem is that the output is htmlencoded, it means that my method (wich work as intended in other contexts) is called but the...
5
1593
by: Patrick.O.Ige | last post by:
I have an xml and i'm trying to loop each node... When i do FOR EACH i seem not to get my desired result I want to loop through and get only the values that matches the question i specified with the corresponding answers? I don't want to retrieve all the Answer and VoteAnswers nodes <xsl:for-each select="NSurveyVoter/Voter/Question/Answer"> <xsl:value-of select="Answer/Answer/text()"/>
2
2095
by: 张韡武 | last post by:
We have preffered language set as variable in xslt: <xsl:variable name="preferred_language"> zh </xsl:variable> Data: <name xml:lang="de">Raw Materials (Mining incl.)</name> <name xml:lang="zh">原材料(包括采矿业) </name>
3
2324
by: Chrism2671 | last post by:
I'm new to XSLT/XML and I have a very simple, quick question. i've been trying to convert simple xml files into CSV files and have made a simple XSLT template using the w3 tutorials, but it doesn't seem to display anything. It does display plain text I enter into the templates, the value-of tags just render whitespace. If anybody can write a template of just a few lines just to demonstrate how to get it to display something from this XML...
0
1223
by: ManWithNoName | last post by:
The following question is related to this thread: XSLT, document() function, filename, read non-standard/English characters (like ) I have a XML file with a non-English character in its name (e.g. ".xml"). The file is loaded in a XSLT file with the XSLT function document(). While the XSLT document is being processed and the result shown (e.g. background colour, title, text in the XSLT document) , the document (".xml") and its content...
2
2499
by: astroboiii | last post by:
New to the whole xml thing and finding w3schools to be an excellent resource. Now down to my question: I have several xml files I need to parse through and grab relevant information from and produce a new xml file. This needs to be automated through ant. The ant script is working fine, and I am usign the <transform> function to use my xslt file and go through all the required xml files, parse them, style them, and ultimately generate my...
0
8466
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
1
8590
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
8659
tracyyun
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...
0
7410
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 projectplanning, coding, testing, and deploymentwithout 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...
1
6211
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
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
4387
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2798
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
2
1790
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.