Problem is having attributes as a part self closing tag's

Discussion in 'XML' started by Amit, May 21, 2007.

  1. Amit

    Amit Guest

    Hello Everyone,

    This is the code I am using..

    <xsl:variable name="var_Temp">
    <xsl:value-of select="../ParentNode/ChildNode/Node"/>
    </xsl:variable>

    <xsl:element name="MyNode">
    <xsl:attribute name="attr1">
    <xsl:text>attr1 value</xsl:text>
    </xsl:attribute>
    <xsl:attribute name="attr2">
    <xsl:value-of select="$var_Temp"/>
    </xsl:attribute>
    </xsl:element>

    Using the above code I get an output looking like

    <MyNode attr1="attr1 value" attr2="Some Value">
    </MyNode >

    But I need the output to look like this, basically i don't want the
    ending tag.

    <MyNode attr1="attr1 value" attr2="Some Value" />

    It would be real nice, if someone can suggest me some alternatives for
    this.

    Regards
    - Amit Gupta
     
    Amit, May 21, 2007
    #1
    1. Advertising

  2. Amit

    Ixa Guest

    > Using the above code I get an output looking like
    >
    > <MyNode attr1="attr1 value" attr2="Some Value">
    > </MyNode >


    Apparently your XSLT processor has a bug; it should behave as you
    expect (creating an empty element without text node). For example, your
    XSLT template works properly with 'xsltproc'.

    > alternatives for this


    As a workaround (if changing software is not an option), how about
    removing all linefeeds from the template? Maybe the processor gets one
    of those linefeeds included accidently to result, and this approach
    could prevent this?

    ---8<---8<---
    <xsl:element name="MyNode"><xsl:attribute name="attr1"><xsl:text>attr1
    value</xsl:text></xsl:attribute><xsl:attribute
    name="attr2"><xsl:value-of
    select="$var_Temp"/></xsl:attribute></xsl:element>
    ---8<---8<---

    --
    Ixa
     
    Ixa, May 24, 2007
    #2
    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. Ralf W. Grosse-Kunstleve
    Replies:
    16
    Views:
    601
    Lonnie Princehouse
    Jul 11, 2005
  2. Ralf W. Grosse-Kunstleve
    Replies:
    18
    Views:
    606
    Bengt Richter
    Jul 11, 2005
  3. Ralf W. Grosse-Kunstleve
    Replies:
    2
    Views:
    414
    Dan Sommers
    Jul 12, 2005
  4. falcon
    Replies:
    0
    Views:
    385
    falcon
    Jul 31, 2005
  5. Amit
    Replies:
    6
    Views:
    426
    Peter Flynn
    May 21, 2007
Loading...

Share This Page