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

A

Amit

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
 
M

Martin Honnen

Amit said:
<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?
 
A

Amit

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?

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
 
M

Martin Honnen

Amit said:
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.
 
R

Richard Tobin

Amit said:
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
 
J

Jim Garrison

Richard said:
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?
 
P

Peter Flynn

Amit said:
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
 

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

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top