Results 1 to 10 of 10

Thread: Indent XML (without recursion)

Hybrid View

  1. #1
    New Member
    Join Date
    Feb 2005
    Posts
    5

    Exclamation Re: Indent XML (without recursion)

    Your XSL based code works great, but there is one change I'm having some trouble implementing. What needs to change in the XSL file in order to not add an end tag? For example,

    I don't want this:
    <element attribute="value"/>

    to be changed to this:
    <element attribute="value">
    </element>

    I know it's just a matter of figuring out the XSL syntax, but I don't have time to learn XSL just to make this one change. Thanks for the help.

  2. #2
    New Member Jade Fox's Avatar
    Join Date
    Jan 2007
    Posts
    1

    Re: Indent XML (without recursion)

    Quote Originally Posted by takedownca
    Your XSL based code works great, but there is one change I'm having some trouble implementing. What needs to change in the XSL file in order to not add an end tag? For example,

    I don't want this:
    <element attribute="value"/>

    to be changed to this:
    <element attribute="value">
    </element>

    I know it's just a matter of figuring out the XSL syntax, but I don't have time to learn XSL just to make this one change. Thanks for the help.
    I changed the XSL_FILE to the following, and it appears to have solved the problem. I haven't debugged it, but it works for me. Not exactly sure why it works, though. My XPath and XSL is pretty rusty.

    VB Code:
    1. XSL_FILE = _
    2.             "<?xml version=" & QT & "1.0" & QT & " encoding=" & QT & "UTF-8" & QT & "?>" & vbCrLf & _
    3.             "<xsl:stylesheet version=" & QT & "1.0" & QT & " xmlns:xsl=" & QT & "http://www.w3.org/1999/XSL/Transform" & QT & ">" & vbCrLf & _
    4.             "     <xsl:output method=" & QT & "xml" & QT & " version=" & QT & "1.0" & QT & " encoding=" & QT & "UTF-8" & QT & " indent=" & QT & sIndent & QT & "/>" & vbCrLf & _
    5.             "     <xsl:template match=" & QT & "@* | node()[count(*)>0]" & QT & ">" & vbCrLf & _
    6.             "          <xsl:copy>" & vbCrLf & _
    7.             "               <xsl:apply-templates select=" & QT & "@* | node()" & QT & " />" & vbCrLf & _
    8.             "          </xsl:copy>" & vbCrLf & _
    9.             "     </xsl:template>" & vbCrLf & _
    10.             "     <xsl:template match=" & QT & "node()[count(*)=0]" & QT & ">" & vbCrLf & _
    11.             "          <xsl:copy>" & vbCrLf & _
    12.             "               <xsl:apply-templates select=" & QT & "@*" & QT & " />" & vbCrLf & _
    13.             "          </xsl:copy>" & vbCrLf & _
    14.             "     </xsl:template>" & vbCrLf & _
    15.             "</xsl:stylesheet>"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width