- From: Loren Cahlander <loren.cahlander@gmail.com>
- Date: Wed, 21 Nov 2012 13:10:36 -0600
- To: G. Ken Holman <gkholman@cranesoftwrights.com>
- Cc: xmlschema-dev@w3.org
- Message-Id: <F02755E6-3E11-43D8-B656-EB124E2987C4@gmail.com>
That fixed it. I have added some additional code including calling normalize-space() to strip leading and trailing spaces from the comments.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">
<!--don't preserve any comments that are followed by element declarations-->
<xsl:template match="
comment()[following-sibling::node()[not(self::text())][1][self::xs:element]]">
<!--do nothing with this comment-->
</xsl:template>
<!--act on element declarations preceded by comments-->
<xsl:template match="
xs:element[preceding-sibling::node()[not(self::text())][1][self::comment()]]">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xs:annotation>
<xs:documentation>
<p xmlns="http://purl.oclc.org/dsdl/schematron"><xsl:value-of select="normalize-space(preceding-sibling::comment()[1])"/></p>
</xs:documentation>
</xs:annotation>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<!--don't preserve any comments that are followed by simpleType declarations-->
<xsl:template match="
comment()[following-sibling::node()[not(self::text())][1][self::xs:simpleType]]">
<!--do nothing with this comment-->
</xsl:template>
<!--act on simpleType declarations preceded by comments-->
<xsl:template match="
xs:simpleType[preceding-sibling::node()[not(self::text())][1][self::comment()]]">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xs:annotation>
<xs:documentation>
<p xmlns="http://purl.oclc.org/dsdl/schematron"><xsl:value-of select="normalize-space(preceding-sibling::comment()[1])"/></p>
</xs:documentation>
</xs:annotation>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<!--don't preserve any comments that are followed by complexType declarations-->
<xsl:template match="
comment()[following-sibling::node()[not(self::text())][1][self::xs:complexType]]">
<!--do nothing with this comment-->
</xsl:template>
<!--act on complexType declarations preceded by comments-->
<xsl:template match="
xs:complexType[preceding-sibling::node()[not(self::text())][1][self::comment()]]">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xs:annotation>
<xs:documentation>
<p xmlns="http://purl.oclc.org/dsdl/schematron"><xsl:value-of select="normalize-space(preceding-sibling::comment()[1])"/></p>
</xs:documentation>
</xs:annotation>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()"><!--identity for all other nodes-->
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Received on Wednesday, 21 November 2012 19:11:08 UTC