XSLT schema

The generated XSLT stylesheet used as a schema is deliberately more verbose. It generates a single line of text output for each occurrence of selector in the input which indicates whether or not the value of said selector matches the generated regular expression or not. Figure 2, “XSLT schema, validation” shows a pared-down version of the generated XSLT stylesheet. Again, GENERATED_REGEXP_HERE indicates where in the output the generation routine places the regular expression.

Figure 2. XSLT schema, validation

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  version="3.0">

  <xsl:variable name="selector_regex">
    <xsl:text>GENERATED_REGEXP_HERE</xsl:text>
  </xsl:variable>
  <xsl:variable 
    name="anchored_selector_regex" 
    select="'^'||$selector_regex"/>
    
  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:text>&#x0A;</xsl:text>
    <xsl:apply-templates select="//*[@selector]"/>
  </xsl:template>
  
  <xsl:template match="*">
    <xsl:value-of select="'selector “'
                          ||@selector
                          ||'” is&#x09;&#x09;'"/>
    <xsl:if 
      test="not( matches( @selector, $anchored_selector_regex ) )">NOT </xsl:if>
    <xsl:value-of select="'valid.&#x0A;'"/>
  </xsl:template>

</xsl:stylesheet>