simple xslt problem/question

C

chonkme

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
 
M

Martin Honnen

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.
 
C

chonkme

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.
 
M

Martin Honnen

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
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="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>
 
C

chonkme

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
 
M

Martin Honnen

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,843
Latest member
WizcraftEntertainmentAgen

Latest Threads

Top