<xsl:stylesheet xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:pat="http://www.w3.org/2002/ws/databinding/patterns/6/09/" xmlns:ex="http://www.w3.org/2002/ws/databinding/examples/6/09/" xmlns:soap11enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl11="http://schemas.xmlsoap.org/wsdl/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>
   <xsl:output method="xml" indent="yes"/>
   <xsl:param name="examples">../patterns/examples.xml</xsl:param>
   <xsl:template match="/">
      <axsl:stylesheet version="2.0">
         <axsl:import href="../common/example-to-html.xsl"/>
         <axsl:preserve-space elements="axsl:text"/>
         <axsl:output method="xml" indent="yes"/>
         <axsl:template match="/">
            <ex:examples wsdlNamespace="http://www.w3.org/2002/ws/databinding/examples/6/09/" targetNamespace="http://www.w3.org/2002/ws/databinding/examples/6/09/">
               <ex:ns prefix="ex" uri="http://www.w3.org/2002/ws/databinding/examples/6/09/"/>
               <ex:ns prefix="log" uri="http://www.w3.org/2002/ws/databinding/log/6/09/"/>
               <ex:ns prefix="xs" uri="http://www.w3.org/2001/XMLSchema"/>
               <ex:ns prefix="xsi" uri="http://www.w3.org/2001/XMLSchema-instance"/>
               <ex:ns prefix="soap11enc" uri="http://schemas.xmlsoap.org/soap/envelope/"/>
               <ex:ns prefix="soap11" uri="http://schemas.xmlsoap.org/soap/envelope/"/>
               <ex:ns prefix="wsdl11" uri="http://schemas.xmlsoap.org/wsdl/"/>
               <xsl:comment>*generated*</xsl:comment>
               <xsl:apply-templates select="pat:patterns/pat:pattern"/>
            </ex:examples>
         </axsl:template>
      </axsl:stylesheet>
   </xsl:template>
   <xsl:template match="pat:pattern">
      <xsl:variable name="id" select="@xml:id"/>
      <xsl:variable name="xpath" select="pat:xpath"/>
      <xsl:for-each select="document($examples)//ex:example[@xml:id = $id or @pattern = $id]">
         <xsl:variable name="exampleId" select="@xml:id"/>
         <ex:example>
            <xsl:attribute name="xml:id">
               <xsl:value-of select="$exampleId"/>
            </xsl:attribute>
            <xsl:attribute name="pattern">
               <xsl:value-of select="$id"/>
            </xsl:attribute>
            <pat:xpath>
               <xsl:value-of select="$xpath"/>
            </pat:xpath>
            <xsl:if test="ex:types">
               <ex:types>
                     <axsl:call-template name="example-to-string">
                        <axsl:with-param name="node-set" select="ex:examples/ex:example[@xml:id='{$exampleId}']/ex:types"/>
                        <axsl:with-param name="flag-nodes" select="ex:examples/ex:example[@xml:id='{$exampleId}']/ex:types//xs:schema/{$xpath}"/>
                     </axsl:call-template>
               </ex:types>
            </xsl:if>
            <xsl:if test="ex:typedef">
               <ex:typedef>
                     <axsl:call-template name="example-to-string">
                        <axsl:with-param name="node-set" select="ex:examples/ex:example[@xml:id='{$exampleId}']/ex:typedef"/>
                        <axsl:with-param name="flag-nodes" select="ex:examples/ex:example[@xml:id='{$exampleId}']/ex:typedef/{$xpath}"/>
                     </axsl:call-template>
               </ex:typedef>
            </xsl:if>
            <axsl:for-each select="ex:examples/ex:example[@xml:id='{$exampleId}']/ex:instance">
               <axsl:copy-of select="."/>
            </axsl:for-each>
         </ex:example>
      </xsl:for-each>
   </xsl:template>
</xsl:stylesheet>

