Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to combine these two xsl file
    primarykey
    data
    text
    <p>I have a schematron file which has abstract pattern,I want to use a xsl file to tranform this file to a file which does not have abstract pattern,all of abstract patterns are instances. the problem is when I instance the abstract pattern ,if I provide a @id attribute in the <code>&lt;pattern&gt;</code> everything is OK.without the @id,paremeter in the abstract pattern could not be replaced correctly the schematron file is as follows</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;schema xmlns="http://purl.oclc.org/dsdl/schematron"&gt; &lt;title&gt;Table abstract patterns&lt;/title&gt; &lt;pattern abstract="true" id="table"&gt; &lt;rule context="$table"&gt; &lt;assert test="$row"&gt;A table has at least one row&lt;/assert&gt; &lt;/rule&gt; &lt;rule context="$row"&gt; &lt;assert test="$cell"&gt;A table row has at least one cell&lt;/assert&gt; &lt;/rule&gt; &lt;/pattern&gt; &lt;pattern is-a="table"&gt; &lt;param name="table" value="table"/&gt; &lt;param name="row" value="tr"/&gt; &lt;param name="cell" value="td"/&gt; &lt;/pattern&gt; &lt;/schema&gt; </code></pre> <p>the xsl file is</p> <pre><code>&lt;xslt:stylesheet version="1.0" xmlns:xslt="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:iso="http://purl.oclc.org/dsdl/schematron" xmlns:nvdl="http://purl.oclc.org/dsdl/nvdl" xmlns:iae="http://www.schematron.com/namespace/iae" &gt; &lt;xslt:param name="schema-id"&gt;&lt;/xslt:param&gt; &lt;!-- Driver for the mode --&gt; &lt;xsl:template match="/"&gt; &lt;xsl:apply-templates select="." mode="iae:go" /&gt; &lt;/xsl:template&gt; &lt;!-- ================================================================================== --&gt; &lt;!-- Normal processing rules --&gt; &lt;!-- ================================================================================== --&gt; &lt;!-- Output only the selected schema --&gt; &lt;xslt:template match="iso:schema" &gt; &lt;xsl:if test="string-length($schema-id) =0 or @id= $schema-id "&gt; &lt;xslt:copy&gt; &lt;xslt:copy-of select="@*" /&gt; &lt;xslt:apply-templates mode="iae:go" /&gt; &lt;/xslt:copy&gt; &lt;/xsl:if&gt; &lt;/xslt:template&gt; &lt;!-- Strip out any foreign elements above the Schematron schema . --&gt; &lt;xslt:template match="*[not(ancestor-or-self::iso:*)]" mode="iae:go" &gt; &lt;xslt:apply-templates mode="iae:go" /&gt; &lt;/xslt:template&gt; &lt;!-- ================================================================================== --&gt; &lt;!-- Handle Schematron abstract pattern preprocessing --&gt; &lt;!-- abstract-to-real calls do-pattern calls macro-expand calls multi-macro-expand replace-substring --&gt; &lt;!-- ================================================================================== --&gt; &lt;!-- Abstract patterns allow you to say, for example &lt;pattern name="htmlTable" is-a="table"&gt; &lt;param name="row" value="html:tr"/&gt; &lt;param name="cell" value="html:td" /&gt; &lt;param name="table" value="html:table" /&gt; &lt;/pattern&gt; For a good introduction, see Uche Ogbujii's article for IBM DeveloperWorks "Discover the flexibility of Schematron abstract patterns" http://www-128.ibm.com/developerworks/xml/library/x-stron.html However, note that ISO Schematron uses @name and @value attributes on the iso:param element, and @id not @name on the pattern element. --&gt; &lt;!-- Suppress declarations of abstract patterns --&gt; &lt;xslt:template match="iso:pattern[@abstract='true']" mode="iae:go" &gt; &lt;xslt:comment&gt;Suppressed abstract pattern &lt;xslt:value-of select="@id"/&gt; was here&lt;/xslt:comment&gt; &lt;/xslt:template&gt; &lt;!-- Suppress uses of abstract patterns --&gt; &lt;xslt:template match="iso:pattern[@is-a]" mode="iae:go" &gt; &lt;xslt:comment&gt;Start pattern based on abstract &lt;xslt:value-of select="@is-a"/&gt;&lt;/xslt:comment&gt; &lt;xslt:call-template name="iae:abstract-to-real" &gt; &lt;xslt:with-param name="caller" select="@id" /&gt; &lt;xslt:with-param name="is-a" select="@is-a" /&gt; &lt;/xslt:call-template&gt; &lt;/xslt:template&gt; &lt;!-- output everything else unchanged --&gt; &lt;xslt:template match="*" priority="-1" mode="iae:go" &gt; &lt;xslt:copy&gt; &lt;xslt:copy-of select="@*" /&gt; &lt;xslt:apply-templates mode="iae:go"/&gt; &lt;/xslt:copy&gt; &lt;/xslt:template&gt; &lt;!-- Templates for macro expansion of abstract patterns --&gt; &lt;!-- Sets up the initial conditions for the recursive call --&gt; &lt;xslt:template name="iae:macro-expand"&gt; &lt;xslt:param name="caller"/&gt; &lt;xslt:param name="text" /&gt; &lt;xslt:call-template name="iae:multi-macro-expand"&gt; &lt;xslt:with-param name="caller" select="$caller"/&gt; &lt;xslt:with-param name="text" select="$text"/&gt; &lt;xslt:with-param name="paramNumber" select="1"/&gt; &lt;/xslt:call-template&gt; &lt;/xslt:template&gt; &lt;!-- Template to replace the current parameter and then recurse to replace subsequent parameters. --&gt; &lt;xslt:template name="iae:multi-macro-expand"&gt; &lt;xslt:param name="caller"/&gt; &lt;xslt:param name="text" /&gt; &lt;xslt:param name="paramNumber" /&gt; &lt;xslt:choose&gt; &lt;xslt:when test="//iso:pattern[@id=$caller]/iso:param[ $paramNumber]"&gt; &lt;xslt:call-template name="iae:multi-macro-expand"&gt; &lt;xslt:with-param name="caller" select="$caller"/&gt; &lt;xslt:with-param name="paramNumber" select="$paramNumber + 1"/&gt; &lt;xslt:with-param name="text" &gt; &lt;xslt:call-template name="iae:replace-substring"&gt; &lt;xslt:with-param name="original" select="$text"/&gt; &lt;xslt:with-param name="substring" select="concat('$', //iso:pattern[@id=$caller]/iso:param[ $paramNumber ]/@name)"/&gt; &lt;xslt:with-param name="replacement" select="//iso:pattern[@id=$caller]/iso:param[ $paramNumber ]/@value"/&gt; &lt;/xslt:call-template&gt; &lt;/xslt:with-param&gt; &lt;/xslt:call-template&gt; &lt;/xslt:when&gt; &lt;xslt:otherwise&gt;&lt;xslt:value-of select="$text" /&gt;&lt;/xslt:otherwise&gt; &lt;/xslt:choose&gt; &lt;/xslt:template&gt; &lt;!-- generate the real pattern from an abstract pattern + parameters--&gt; &lt;xslt:template name="iae:abstract-to-real" &gt; &lt;xslt:param name="caller"/&gt; &lt;xslt:param name="is-a" /&gt; &lt;xslt:for-each select="//iso:pattern[@id= $is-a]"&gt; &lt;xslt:copy&gt; &lt;xslt:choose&gt; &lt;xslt:when test=" string-length( $caller ) = 0"&gt; &lt;xslt:attribute name="id"&gt;&lt;xslt:value-of select="concat( generate-id(.) , $is-a)" /&gt;&lt;/xslt:attribute&gt; &lt;/xslt:when&gt; &lt;xslt:otherwise&gt; &lt;xslt:attribute name="id"&gt;&lt;xslt:value-of select="$caller" /&gt;&lt;/xslt:attribute&gt; &lt;/xslt:otherwise&gt; &lt;/xslt:choose&gt; &lt;xslt:apply-templates select="*|text()" mode="iae:do-pattern" &gt; &lt;xslt:with-param name="caller"&gt;&lt;xslt:value-of select="$caller"/&gt;&lt;/xslt:with-param&gt; &lt;/xslt:apply-templates&gt; &lt;/xslt:copy&gt; &lt;/xslt:for-each&gt; &lt;/xslt:template&gt; &lt;!-- Generate a non-abstract pattern --&gt; &lt;xslt:template mode="iae:do-pattern" match="*"&gt; &lt;xslt:param name="caller"/&gt; &lt;xslt:copy&gt; &lt;xslt:for-each select="@*[name()='test' or name()='context' or name()='select']"&gt; &lt;xslt:attribute name="{name()}"&gt; &lt;xslt:call-template name="iae:macro-expand"&gt; &lt;xslt:with-param name="text"&gt;&lt;xslt:value-of select="."/&gt;&lt;/xslt:with-param&gt; &lt;xslt:with-param name="caller"&gt;&lt;xslt:value-of select="$caller"/&gt;&lt;/xslt:with-param&gt; &lt;/xslt:call-template&gt; &lt;/xslt:attribute&gt; &lt;/xslt:for-each&gt; &lt;xslt:copy-of select="@*[name()!='test'][name()!='context'][name()!='select']" /&gt; &lt;xsl:for-each select="node()"&gt; &lt;xsl:choose&gt; &lt;!-- Experiment: replace macros in text as well, to allow parameterized assertions and so on, without having to have spurious &lt;iso:value-of&gt; calls and multiple delimiting --&gt; &lt;xsl:when test="self::text()"&gt; &lt;xslt:call-template name="iae:macro-expand"&gt; &lt;xslt:with-param name="text"&gt;&lt;xslt:value-of select="."/&gt;&lt;/xslt:with-param&gt; &lt;xslt:with-param name="caller"&gt;&lt;xslt:value-of select="$caller"/&gt;&lt;/xslt:with-param&gt; &lt;/xslt:call-template&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xslt:apply-templates select="." mode="iae:do-pattern"&gt; &lt;xslt:with-param name="caller"&gt;&lt;xslt:value-of select="$caller"/&gt;&lt;/xslt:with-param&gt; &lt;/xslt:apply-templates&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:for-each&gt; &lt;/xslt:copy&gt; &lt;/xslt:template&gt; &lt;!-- UTILITIES --&gt; &lt;!-- Simple version of replace-substring function --&gt; &lt;xslt:template name="iae:replace-substring"&gt; &lt;xslt:param name="original" /&gt; &lt;xslt:param name="substring" /&gt; &lt;xslt:param name="replacement" select="''"/&gt; &lt;xsl:choose&gt; &lt;xsl:when test="not($original)" /&gt; &lt;xsl:when test="not(string($substring))"&gt; &lt;xsl:value-of select="$original" /&gt; &lt;/xsl:when&gt; &lt;xsl:when test="contains($original, $substring)"&gt; &lt;xsl:variable name="before" select="substring-before($original, $substring)" /&gt; &lt;xsl:variable name="after" select="substring-after($original, $substring)" /&gt; &lt;xsl:value-of select="$before" /&gt; &lt;xsl:value-of select="$replacement" /&gt; &lt;!-- recursion --&gt; &lt;xsl:call-template name="iae:replace-substring"&gt; &lt;xsl:with-param name="original" select="$after" /&gt; &lt;xsl:with-param name="substring" select="$substring" /&gt; &lt;xsl:with-param name="replacement" select="$replacement" /&gt; &lt;/xsl:call-template&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;!-- no substitution --&gt; &lt;xsl:value-of select="$original" /&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xslt:template&gt; &lt;/xslt:stylesheet&gt; </code></pre> <p>my expected result is</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;schema xmlns="http://purl.oclc.org/dsdl/schematron"&gt; &lt;title&gt;Table abstract patterns&lt;/title&gt; &lt;pattern id="table1"&gt; &lt;rule context="table"&gt; &lt;assert test="tr"&gt;A table has at least one row&lt;/assert&gt; &lt;/rule&gt; &lt;rule context="tr"&gt; &lt;assert test="td"&gt;A table row has at least one cell&lt;/assert&gt; &lt;/rule&gt; &lt;/pattern&gt; &lt;/schema&gt; </code></pre> <p>now I have a preprocess xsl as follows ,if I use this one first and the above one next ,I will get what I want</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet xmlns:xslt="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:iso="http://purl.oclc.org/dsdl/schematron" xmlns:nvdl="http://purl.oclc.org/dsdl/nvdl" xmlns:iae="http://www.schematron.com/namespace/iae" &gt; &lt;xsl:template match="node() | @*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node() | @*" /&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="iso:pattern[not(@id)]"&gt; &lt;xslt:comment&gt;Add @id for pattern &lt;/xslt:comment&gt; &lt;xsl:copy&gt; &lt;xslt:comment&gt;Add @id for pattern &lt;/xslt:comment&gt; &lt;xsl:attribute name="id"&gt; &lt;xslt:value-of select="generate-id(.) "/&gt; &lt;/xsl:attribute&gt; &lt;xsl:apply-templates select="node() | @*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>How to combine these two file together?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload