Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > simple xslt problem/question

Reply
Thread Tools

simple xslt problem/question

 
 
chonkme@gmail.com
Guest
Posts: n/a
 
      05-17-2005
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

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      05-17-2005


http://www.velocityreviews.com/forums/(E-Mail Removed) 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/
 
Reply With Quote
 
 
 
 
chonkme@gmail.com
Guest
Posts: n/a
 
      05-17-2005
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:ControlActProcess moodCode='RQO'>
<hl7:code code='QUQI_TE000002'/>
<hl7:subject>
<hl7:act moodCode='EVN'>
<hl7:result>Weight 2001-01-12 11.2</hl7:result>
<hl7:result>Weight 2001-01-13 11.2</hl7:result>
</hl7:act>
</hl7:subject>
<hl7:queryAck>
<hl7:queryResponseCode code='OK'/>
<hl7:resultTotalQuantity value='2'/>
</hl7:queryAck>
</hl7:ControlActProcess>

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.

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      05-17-2005


(E-Mail Removed) 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:ControlActProcess moodCode='RQO'>
> <hl7:code code='QUQI_TE000002'/>
> <hl7:subject>
> <hl7:act moodCode='EVN'>
> <hl7:result>Weight 2001-01-12 11.2</hl7:result>
> <hl7:result>Weight 2001-01-13 11.2</hl7:result>
> </hl7:act>
> </hl7:subject>
> <hl7:queryAck>
> <hl7:queryResponseCode code='OK'/>
> <hl7:resultTotalQuantity value='2'/>
> </hl7:queryAck>
> </hl7:ControlActProcess>
>
> 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:stylesheet
xmlnssl="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="putpropernamespaceURIhere"
match="h17:result">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:attribute name="id"><xsl:value-of select="generate-id()"
/></xsl:attribute>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
chonkme@gmail.com
Guest
Posts: n/a
 
      05-17-2005
that stylesheet works perfectly, much thanks for the speedy reply and
solution

 
Reply With Quote
 
chonkme@gmail.com
Guest
Posts: n/a
 
      05-17-2005
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

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      05-17-2005


(E-Mail Removed) 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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Including XSLT/XML document within a XSLT document dar_imiro@hotmail.com XML 4 12-13-2005 02:26 AM
Multiple XSLT Transforms using a Controller XSLT sneill@mxlogic.com XML 2 10-19-2005 11:00 AM
ANN: New low-cost XML Editor, XSLT Editor, XSLT Debugger, DTD/Schema Editor Stylus Studio Java 0 08-03-2004 03:53 PM
xslt alone or xslt/java for static site? ted XML 1 01-26-2004 10:41 AM
[XSLT]Passing values from Javascript to a XSLT variable Benjamin Hillsley XML 3 09-25-2003 04:50 AM



Advertisments