Re: Does anyone have a transform to change comments into annotations in an existing schema?

The current contents of the xs:element were not copied when the annotation was added.


On Nov 21, 2012, at 10:09 AM, G. Ken Holman <gkholman@cranesoftwrights.com> wrote:

> Something similar to the following should work for you:
> 
> <?xml version="1.0" encoding="US-ASCII"?>
> <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>
>        <xsl:value-of select="preceding-sibling::comment()[1]"/>
>      </xs:documentation>
>    </xs:annotation>
>  </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>
> 
> What do you mean by "formatting annotations"?  At what point are you formatting them?
> 
> I hope the stylesheet above helps.
> 
> . . . . . . . . Ken
> 
> At 2012-11-21 09:45 -0600, Loren Cahlander wrote:
>> I am looking to transform comments that precede an element and make those comments as an annotation for that element.
>> 
>> for example:
>> 
>> <!-- Information about foo -->
>> <xs:element name="foo-group">
>> .
>> .
>> .
>> </xs:element>
>> 
>> 
>> to
>> 
>> <xs:element name="foo-group">
>> <xs:annotation>
>>  <xs:documentation>Information about foo</xs:documentation>
>> </xs:annotation>
>> </xs:element>
>> 
>> 
>> I have a bunch of schemas that I need to transform.
>> 
>> Another issue is:  Does anyone have a way of formatting the annotations?  Through oXygen, I found that I could add schematron elements within the documentation.  The only one that I found useful was <p xmlns="<http://purl.oclc.org/dsdl/schematron>http://purl.oclc.org/dsdl/schematron"></p>
>> 
>> Has anyone used better formatting of annotations?
>> 
>> Thank you,
>> Loren
> 
> 
> --
> Contact us for world-wide XML consulting and instructor-led training
> Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
> Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/x/
> G. Ken Holman                   mailto:gkholman@CraneSoftwrights.com
> Google+ profile: https://plus.google.com/116832879756988317389/about
> Legal business disclaimers:    http://www.CraneSoftwrights.com/legal
> 
> 

Received on Wednesday, 21 November 2012 17:10:58 UTC