?
Solved

xsl script removing closing tag name and replacing with </>

Posted on 2006-03-21
7
Medium Priority
?
259 Views
Last Modified: 2013-11-19
Hello folks,

Here is an example of my xml file BEFORE running through xsl script:

<root>
   <Image1>img/image1.gif</Image1>
   <Image2>img/image2.gif</Image2>
   <Image3>img/image3.gif</Image3>
<root>

Here is the xml file AFTER running though xsl script:

<root>
   <Image1>img/image1.gif</>
   <Image2>img/image2.gif</>
   <Image3>img/image3.gif</>
<root>

I do not want the end tags to be replaced with </>.  Does anybody know how to force the script to leave as is?

Thanks
0
Comment
Question by:nothing8171
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16248983
Can you post your existing XSL ? Or at least the part that deals with this section.
0
 
LVL 10

Expert Comment

by:pvginkel
ID: 16249205
What XSL processor are you using? I've never seen this behaviour before.
0
 
LVL 1

Author Comment

by:nothing8171
ID: 16249254
XML BEFORE
<Something x="some_data"
                  y="other_data">
</Something>

XSL SCRIPT
<xsl:template match="Something">
    <xsl:copy>
      <xsl:copy-of select="@x"/>
      <xsl:copy-of select="@y"/>
    </xsl:copy>
  </xsl:template>

XML AFTER
<Something x="some_data"
                  y="other_data"/>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Assisted Solution

by:pvginkel
pvginkel earned 200 total points
ID: 16249303
The last example is what is to be expected. I don't think this is something you can get around. What script creates the code in your question and what processor are you using?
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 200 total points
ID: 16249321
<Something x="some_data" y="other_data"/>

is perfectly valid, and is just a shorthand for:

<Something x="some_data" y="other_data">
</Something>

Whereas the snippet you posted earlier actually had the closing Image tag missing which would invalidate the XML. Is this what is happening, or was your original version a typo ?
0
 
LVL 1

Author Comment

by:nothing8171
ID: 16304912
The XSL processor is "Xalan" and I realize this is acceptable, but I am comparing thousands of old files with new files.  The old files have the </Something> and the new ones only </>.  It's an annoyance when performing diffs.
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 600 total points
ID: 16325837
<test></test> and <test /> are equivalent
and you can't tell an XSLT processor to choose either form for empty elements
it is just a syntax difference of no value

you have a good usecase though for being able to add an endtag

what I usually do to force an endtag is just create an comment tag in it
such as <!-- EMPTY -->
You can then easily get rid of that using SED or AWK, PYTHON,....

doing so, I once discovered something that only works in Xalan (it did for me in Xalan for Java)
but that can be helpful for you
create a comment inside a parameter (global one) like this
    <xsl:param name="empty"><xsl:comment>EMPTY</xsl:comment></xsl:param>
then use that parameter, like this
            <text><xsl:value-of select="$empty"/></text>
you would expect to get this
<text><!-- EMPTY --></text>
instead you get this in Xalan
<text></text>
and this in Saxon
<text/>

so you can't rely on this to go well each time,
but for this once and since you are using Xalan
you might as well be lucky
call it an undocumented feature :-)

cheers

Geert
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question