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 wrote:

    > <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" />


    You should get
    <MyNode attr1="attr1 value" attr2="Some Value"></MyNode>
    but certainly not white space between the start tag and end tag.
    As for
    <MyNode attr1="attr1 value" attr2="Some Value" />
    or
    <MyNode attr1="attr1 value" attr2="Some Value"/>
    that is the same as
    <MyNode attr1="attr1 value" attr2="Some Value"></MyNode>
    so it should not matter.

    Which XSLT processor are you using that inserts the white space?




    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, May 21, 2007
    #2
    1. Advertising

  3. Amit

    Amit Guest

    > You should get
    > <MyNode attr1="attr1 value" attr2="Some Value"></MyNode>
    > but certainly not white space between the start tag and end tag.
    > As for
    > <MyNode attr1="attr1 value" attr2="Some Value" />
    > or
    > <MyNode attr1="attr1 value" attr2="Some Value"/>
    > that is the same as
    > <MyNode attr1="attr1 value" attr2="Some Value"></MyNode>
    > so it should not matter.
    >
    > Which XSLT processor are you using that inserts the white space?
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/


    Hello Martin,

    My Problem is not on white spaces, the problem is ending tag.

    I know <MyNode attr1="attr1 value" attr2="Some Value"></MyNode> and
    <MyNode attr1="attr1 value" attr2="Some Value"/> is equivalent.

    but the third party application which is going to import the xml,
    doesn't understand this.
    For successful import, there should not be any ending xml tag.

    Regards
    - Amit Gupta
     
    Amit, May 21, 2007
    #3
  4. Amit wrote:

    > I know <MyNode attr1="attr1 value" attr2="Some Value"></MyNode> and
    > <MyNode attr1="attr1 value" attr2="Some Value"/> is equivalent.
    >
    > but the third party application which is going to import the xml,
    > doesn't understand this.
    > For successful import, there should not be any ending xml tag.


    Which XSLT processor do you use? Check whether it supports any settings
    to enforce serializing empty elements as <element-name/>, that is your
    only chance.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, May 21, 2007
    #4
  5. In article <>,
    Amit <> wrote:

    >I know <MyNode attr1="attr1 value" attr2="Some Value"></MyNode> and
    ><MyNode attr1="attr1 value" attr2="Some Value"/> is equivalent.


    >but the third party application which is going to import the xml,
    >doesn't understand this.


    Then get a different application! XML is supposed to be a standard.
    Programs that accept odd subsets of XML should be rejected.

    I realise that you may not find this helpful, but I really don't want
    to encourage the people who write such programs. I want their
    products to fail.

    -- Richard
    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
     
    Richard Tobin, May 21, 2007
    #5
  6. Amit

    Jim Garrison Guest

    Richard Tobin wrote:
    > In article <>,
    > Amit <> wrote:
    >
    >> I know <MyNode attr1="attr1 value" attr2="Some Value"></MyNode> and
    >> <MyNode attr1="attr1 value" attr2="Some Value"/> is equivalent.

    >
    >> but the third party application which is going to import the xml,
    >> doesn't understand this.

    >
    > Then get a different application! XML is supposed to be a standard.
    > Programs that accept odd subsets of XML should be rejected.
    >
    > I realise that you may not find this helpful, but I really don't want
    > to encourage the people who write such programs. I want their
    > products to fail.


    In other words, the two forms

    <tag attrs.../>

    and

    <tag attrs...></tag>

    are equivalent in standard XML and must be interpreted the same
    by any standard XML processor. If the application that processes
    this makes a distinction between the two forms, then it is
    requiring non-standard XML, and is incorrect. You should
    file a bug report with the provider of that application.

    Are you absolutely SURE the ending tag is the problem?
     
    Jim Garrison, May 21, 2007
    #6
  7. Amit

    Peter Flynn Guest

    Amit wrote:
    >> You should get
    >> <MyNode attr1="attr1 value" attr2="Some Value"></MyNode>
    >> but certainly not white space between the start tag and end tag.
    >> As for
    >> <MyNode attr1="attr1 value" attr2="Some Value" />
    >> or
    >> <MyNode attr1="attr1 value" attr2="Some Value"/>
    >> that is the same as
    >> <MyNode attr1="attr1 value" attr2="Some Value"></MyNode>
    >> so it should not matter.
    >>
    >> Which XSLT processor are you using that inserts the white space?
    >>
    >> --
    >>
    >> Martin Honnen
    >> http://JavaScript.FAQTs.com/

    >
    > Hello Martin,
    >
    > My Problem is not on white spaces, the problem is ending tag.
    >
    > I know <MyNode attr1="attr1 value" attr2="Some Value"></MyNode> and
    > <MyNode attr1="attr1 value" attr2="Some Value"/> is equivalent.
    >
    > but the third party application which is going to import the xml,
    > doesn't understand this.


    Then the third-party application is broken and must be replaced.

    If you continue to use broken software, you will eventually get broken
    data. Replacing the software with something that works properly is much
    cheaper than trying to mend the broken data (and the broken decisions
    that were made using it).

    > For successful import, there should not be any ending xml tag.


    As a temporary solution, pass the output through a stream filter to
    delete the unwanted end-tags and change the preceding > with />

    ///Peter
     
    Peter Flynn, May 21, 2007
    #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. Ralf W. Grosse-Kunstleve
    Replies:
    16
    Views:
    587
    Lonnie Princehouse
    Jul 11, 2005
  2. Ralf W. Grosse-Kunstleve
    Replies:
    18
    Views:
    601
    Bengt Richter
    Jul 11, 2005
  3. Ralf W. Grosse-Kunstleve
    Replies:
    2
    Views:
    406
    Dan Sommers
    Jul 12, 2005
  4. falcon
    Replies:
    0
    Views:
    379
    falcon
    Jul 31, 2005
  5. Amit
    Replies:
    1
    Views:
    340
Loading...

Share This Page