[Bug 8573] New: F.1 Stylesheet for chameleons invalid

http://www.w3.org/Bugs/Public/show_bug.cgi?id=8573

           Summary: F.1 Stylesheet for chameleons invalid
           Product: XML Schema
           Version: 1.1 only
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Structures: XSD Part 1
        AssignedTo: David_E3@VERIFONE.com
        ReportedBy: hrennau@yahoo.de
         QAContact: www-xml-schema-comments@w3.org
                CC: cmsmcq@blackmesatech.com


The stylesheet contains several errors, e.g. referencing the context item
within a stylesheet function. Proposed correction as follows. Another issue -
the stylesheets "forgets" to handle the attribute 'memberTypes' - is dealt with
in a separate bug report.

With kind regards -
Hans-Juergen Rennau




<xsl:transform version="2.0"
               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:f="http://www.w3.org/2008/05/XMLSchema-misc">

  <xsl:param name="newTargetNamespace" as="xs:anyURI" 
      required="yes"/>
  <xsl:param name="prefixForTargetNamespace" as="xs:NCName" 
      select="f:generateUniquePrefix(., 0)"/>

  <xsl:template match="@*|node()">
    <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
  </xsl:template>

  <xsl:template match="xs:schema">
    <xsl:copy>
     <xsl:namespace name="{$prefixForTargetNamespace}" 
       select="$newTargetNamespace"/>
     <xsl:apply-templates select="@*"/>
     <xsl:attribute name="targetNamespace" 
       select="$newTargetNamespace"/>
     <xsl:apply-templates/>
   </xsl:copy>
  </xsl:template>

  <xsl:template match="attribute(*, xs:QName)
      [namespace-uri-from-QName(.)='']">
    <xsl:attribute name="{name()}" 
      select="concat($prefixForTargetNamespace, 
                     ':', 
                     local-name-from-QName(.))"/>
  </xsl:template>

  <xsl:function name="f:generateUniquePrefix" as="xs:NCName">
    <xsl:param name="xsd"/>
    <xsl:param name="try" as="xs:integer"/>
    <xsl:variable name="disallowed" 
      select="distinct-values($xsd//*/in-scope-prefixes(.))"/>
    <xsl:variable name="candidate" 
      select="xs:NCName(concat('p', $try))"/>
    <xsl:sequence select="if ($candidate = $disallowed) then 
                                f:generateUniquePrefix($xsd, $try+1) 
                             else 
                                $candidate"/>
  </xsl:function>

</xsl:transform>


-- 
Configure bugmail: http://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

Received on Thursday, 31 December 2009 16:12:39 UTC