simple xslt problem/question

Discussion in 'XML' started by chonkme@gmail.com, May 17, 2005.

  1. Guest

    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
     
    , May 17, 2005
    #1
    1. Advertising

  2. 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/
     
    Martin Honnen, May 17, 2005
    #2
    1. Advertising

  3. Guest

    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.
     
    , May 17, 2005
    #3
  4. 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
    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>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, May 17, 2005
    #4
  5. Guest

    that stylesheet works perfectly, much thanks for the speedy reply and
    solution
     
    , May 17, 2005
    #5
  6. Guest

    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
     
    , May 17, 2005
    #6
  7. 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/
     
    Martin Honnen, May 17, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stylus Studio
    Replies:
    0
    Views:
    711
    Stylus Studio
    Aug 3, 2004
  2. Benjamin Hillsley
    Replies:
    3
    Views:
    1,700
    Dimitre Novatchev
    Sep 25, 2003
  3. ted
    Replies:
    1
    Views:
    641
    Laurens
    Jan 26, 2004
  4. Replies:
    2
    Views:
    729
    Henry S. Thompson
    Oct 19, 2005
  5. Replies:
    18
    Views:
    2,777
    Joseph Kesselman
    Oct 4, 2006
Loading...

Share This Page