tags:

views:

102

answers:

3

What do I need to do to this:

    <xsl:template match="xs:simpleType">
   <xsl:copy>
  <xsl:copy-of select="node()[not(self::xs:annotation or self::xs:restriction)]|@*"/>
   </xsl:copy>
    </xsl:template>

Currently, this turns out:

<xs:simpleType xmlns:core="urn:org:pesc:core:CoreMain:v1.4.0" name="SINIDType">


</xs:simpleType>

I'd prefer it to look like:

<xs:simpleType name="SINIDType" />
A: 

The serializer is responsible for whether an empty element is emitted as <abc></abc> or <abc/>, and they are exactly equivalent. Some serializers give no option, and will always produce one or the other.

But it might be that you are emitting whitespace between them; in that case you'll have to change the xsl:copy to something else that doesn't include the insignificant whitespace, like by adding or text() = '' to your predicate.

As far as eliminating the xmlns:core namespace declaration, that depends on your context. It will be generated always if there is an element that requires it inside of your type, or if you're using XSLT and haven't excluded the namespace with the @exclude-result-prefixes attribute on the <xsl:stylesheet> root element. And even then, depending on your processor environment, the serializer may "decide" that it wants that namespace output needlessly, since it was in scope in the input.

Also, it's kind of odd to see <xsl:copy> ... <xsl:copy-of .../> ... </xsl:copy>. You really shouldn't wrap the copy-of inside of the copys. Just make it copy-of.

lavinio
+3  A: 

with those blank lines in there, it looks like your select statement is (correctly) selecting your whitespace nodes as well as your elements. try using

select="*[not(self::xs:annotation or self::xs:restriction)]|@*"

which will only match element nodes, not text nodes.

ScottSEA
A: 

Scott - you got it, the output is legible now :)

lavino - I've tried the exclude-result-prefixes as you suggested, but it's not working for me. As you mentioned, it's probably the program but at least I know what to try. Also - I have to use else the output lacks the parent element - copy-of is only giving me the children. Is that a "feature" of XSLT v1.0?

OMG Ponies
@rexem: Since you liked my answer, howzabout marking it as answer for me? I'd appreciate it.
ScottSEA
It's not giving me the checkmark to do it :(
OMG Ponies
Bollocks! I hate it when that happens. :-)
ScottSEA
I voted alls I can, can'ts votes n'more
OMG Ponies