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

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
LVL 1
nothing8171Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
Can you post your existing XSL ? Or at least the part that deals with this section.
pvginkelCommented:
What XSL processor are you using? I've never seen this behaviour before.
nothing8171Author Commented:
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"/>
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

pvginkelCommented:
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?
Carl TawnSystems and Integration DeveloperCommented:
<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 ?
nothing8171Author Commented:
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.
Gertone (Geert Bormans)Information ArchitectCommented:
<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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.