Jump to content

Formatting question


maestrith

Recommended Posts

I use this stylesheet

xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xsl:output method="xml" indent="yes" encoding="UTF-8"/>xsl:template match="@*|node()"xsl:copyxsl:apply-templates select="@*|node()"//xsl:copy/xsl:template/xsl:stylesheet

and it outputs

?xml version="1.0"?>Options>    main value="1">        sub value="2">        /sub>    /main>/Options>

I was wondering if there was a way to make it so that if the sub does not have a text value that it would look like <sub value="2"/>Thanks in advance.

Link to comment
Share on other sites

With XML the syntax forms

<foo></foo>

and

<foo/>

and

<foo />

are all three semantically equivalent (all mark up an empty "foo" element) and it shouldn't matter which form you get as a result of an XSLT transformation.However if you get

<foo></foo>

then additional white space is introduced as that way the "foo" element is no longer empty but has a text node with white space as its child.You haven't shown your input XML, only the XSLT and the result so it is hard to tell whether something goes wrong.Also serialization options are processor specific, you haven't told us which one you use and how you run the transformation.Currently the only change I can suggest is to drop the [mono]indent="yes"[/mono] from the xsl: output as that might introduce additional white space.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...