Path: blob/master/venv/Lib/site-packages/lxml/isoschematron/resources/xsl/XSD2Schtrn.xsl
811 views
<?xml version="1.0" encoding="UTF-8"?>1<!--2based on an original transform by Eddie Robertsson32001/04/21 fn: added support for included schemas42001/06/27 er: changed XMl Schema prefix from xsd: to xs: and changed to the Rec namespace52009/12/10 hj: changed Schematron namespace to ISO URI (Holger Joukl)6-->7<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"8xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns:xs="http://www.w3.org/2001/XMLSchema">9<!-- Set the output to be XML with an XML declaration and use indentation -->10<xsl:output method="xml" omit-xml-declaration="no" indent="yes" standalone="yes"/>11<!-- -->12<!-- match schema and call recursive template to extract included schemas -->13<!-- -->14<xsl:template match="xs:schema">15<!-- call the schema definition template ... -->16<xsl:call-template name="gatherSchema">17<!-- ... with current current root as the $schemas parameter ... -->18<xsl:with-param name="schemas" select="/"/>19<!-- ... and any includes in the $include parameter -->20<xsl:with-param name="includes"21select="document(/xs:schema/xs:*[self::xs:include or self::xs:import or self::xs:redefine]/@schemaLocation)"/>22</xsl:call-template>23</xsl:template>24<!-- -->25<!-- gather all included schemas into a single parameter variable -->26<!-- -->27<xsl:template name="gatherSchema">28<xsl:param name="schemas"/>29<xsl:param name="includes"/>30<xsl:choose>31<xsl:when test="count($schemas) < count($schemas | $includes)">32<!-- when $includes includes something new, recurse ... -->33<xsl:call-template name="gatherSchema">34<!-- ... with current $includes added to the $schemas parameter ... -->35<xsl:with-param name="schemas" select="$schemas | $includes"/>36<!-- ... and any *new* includes in the $include parameter -->37<xsl:with-param name="includes"38select="document($includes/xs:schema/xs:*[self::xs:include or self::xs:import or self::xs:redefine]/@schemaLocation)"/>39</xsl:call-template>40</xsl:when>41<xsl:otherwise>42<!-- we have the complete set of included schemas,43so now let's output the embedded schematron -->44<xsl:call-template name="output">45<xsl:with-param name="schemas" select="$schemas"/>46</xsl:call-template>47</xsl:otherwise>48</xsl:choose>49</xsl:template>50<!-- -->51<!-- output the schematron information -->52<!-- -->53<xsl:template name="output">54<xsl:param name="schemas"/>55<!-- -->56<sch:schema>57<!-- get header-type elements - eg title and especially ns -->58<!-- title (just one) -->59<xsl:copy-of select="$schemas//xs:appinfo/sch:title[1]"/>60<!-- get remaining schematron schema children -->61<!-- get non-blank namespace elements, dropping duplicates -->62<xsl:for-each select="$schemas//xs:appinfo/sch:ns">63<xsl:if test="generate-id(.) =64generate-id($schemas//xs:appinfo/sch:ns[@prefix = current()/@prefix][1])">65<xsl:copy-of select="."/>66</xsl:if>67</xsl:for-each>68<xsl:copy-of select="$schemas//xs:appinfo/sch:phase"/>69<xsl:copy-of select="$schemas//xs:appinfo/sch:pattern"/>70<sch:diagnostics>71<xsl:copy-of select="$schemas//xs:appinfo/sch:diagnostics/*"/>72</sch:diagnostics>73</sch:schema>74</xsl:template>75<!-- -->76</xsl:transform>777879