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

Posted on 2006-03-21
Last Modified: 2013-11-19
Hello folks,

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


Here is the xml file AFTER running though xsl script:


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

Question by:nothing8171
    LVL 52

    Expert Comment

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

    Expert Comment

    What XSL processor are you using? I've never seen this behaviour before.
    LVL 2

    Author Comment

    <Something x="some_data"

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

    <Something x="some_data"
    LVL 10

    Assisted Solution

    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?
    LVL 52

    Assisted Solution

    by:Carl Tawn
    <Something x="some_data" y="other_data"/>

    is perfectly valid, and is just a shorthand for:

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

    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 ?
    LVL 2

    Author Comment

    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.
    LVL 60

    Accepted Solution

    <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
    and this in Saxon

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



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System ( introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
    Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    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 …

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now