Last active
October 9, 2016 17:13
-
-
Save jelovirt/cd100d71f723fd3e25818baa0b2c54ea to your computer and use it in GitHub Desktop.
Inline matching in pseudo-XSLT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:template match="metasyntactic"> | |
<xsl:match select="."> | |
<xsl:case match="foo">foo</xsl:case> | |
<xsl:case match="bar">bar</xsl:case> | |
<xsl:case match="baz">baz</xsl:case> | |
</xsl:match> | |
</xsl:template> |
I don't know anything about Schematron Quick Fix, so I don't really know why you'd use it here. Couldn't you just use XSLT?
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:local="local"
exclude-result-prefixes="local xs"
version="3.0">
<xsl:output method="xml" indent="yes"/>
<xsl:namespace-alias result-prefix="xsl" stylesheet-prefix="local"/>
<xsl:template match="xsl:template[xsl:match]">
<xsl:variable name="mode" select="generate-id(xsl:match)" as="xs:string"/>
<xsl:next-match>
<xsl:with-param name="mode" select="$mode" as="xs:string" tunnel="yes"/>
</xsl:next-match>
<xsl:apply-templates select="xsl:match/xsl:case">
<xsl:with-param name="mode" select="$mode" as="xs:string" tunnel="yes"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="xsl:match">
<xsl:param name="mode" as="xs:string" tunnel="yes"/>
<local:apply-templates>
<xsl:attribute name="mode" select="$mode"/>
<xsl:apply-templates select="@select"/>
</local:apply-templates>
</xsl:template>
<xsl:template match="xsl:case">
<xsl:param name="mode" as="xs:string" tunnel="yes"/>
<local:template mode="{$mode}">
<xsl:sequence select="node()"/>
</local:template>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
But yeah, this kind of thing should really be baked into the language itself, since debugging generated stylesheets isn't a whole lot of fun.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To test this in oXygen, the Schematron schema can be added to the XSLT framework, or you can define a validation scenario (from the validation toolbar drop down, select "Configure Validation Scenario") and add a validation unit that validated the document as an XML document with this schema.