Last active
August 20, 2020 18:16
-
-
Save gimsieke/6879ff14c443ccc52e12a2312906cbed to your computer and use it in GitHub Desktop.
XQuery to report matching XSLT templates with non-tunnel parameters
This file contains hidden or 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
(: This will report matching XSLT templates with non-tunnel parameters. | |
These are dangerous because if a template with higher priority or import | |
precedence intercepts a given template with such a parameter, and then | |
uses <xsl:next-match/> without passing the parameter, the template will | |
not receive the same parameter any more. This might not flag an error, | |
for example if the parameter is declared xs:boolean? or if there is no | |
as attribute at all. This can lead to unexpected behavior. | |
Paste the code in in the oXygen XPath/XQuery Builder or execute it | |
standalone with XQuery-enabled Saxon, and adapt $dir-uri according | |
to you needs. | |
:) | |
declare variable $dir-uri external := 'file:///C:/path/to/project'; | |
<non-tunnel-params> { | |
for $params in collection($dir-uri || '/?match=.*\.xslt?;recurse=yes') | |
//*:template[@match]/*:param[not(@tunnel=('1','yes','true'))] | |
let $bu := base-uri($params) | |
group by $bu | |
return <stylesheet href="{$bu}" | |
count="{count($params)}" | |
names="{sort(distinct-values($params/@name))}"> { | |
for $template in $params/.. | |
return <template match="{$template/@match => normalize-space()}" | |
params="{$template/*:param[not(@tunnel=('1','yes','true'))]/@name}"> { | |
$template/(@priority, @mode), | |
attribute line { saxon:line-number($template) } | |
} </template> | |
} </stylesheet> | |
} </non-tunnel-params> |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<non-tunnel-params> | |
<stylesheet href="file:/C:/cygwin/home/gerrit/Hogrefe/BookTagSet/transpect/bits2hub/xsl/bits2hub.xsl" | |
count="7" | |
names="first-list-para render"> | |
<template match="bio[count(parent::*/*) = 2 and ../contrib]" | |
params="render" | |
mode="bits2hub-default" | |
line="141"/> | |
<template match="*[self::sec or self::title-group or self::ref-list][title]/label" | |
params="render" | |
mode="bits2hub-default" | |
line="183"/> | |
<template match="*[table]/caption" | |
params="render" | |
mode="bits2hub-default" | |
priority="1" | |
line="370"/> | |
<template match="caption[count(*) != count(title)]/title" | |
params="render" | |
mode="bits2hub-default" | |
priority="1" | |
line="391"/> | |
<template match="*[caption[title]]/label" | |
params="render" | |
mode="bits2hub-default" | |
line="411"/> | |
<template match="list-item/p" | |
params="first-list-para" | |
mode="bits2hub-default" | |
line="439"/> | |
<template match="list-item/p[every $child in node() satisfies ($child[self::fig | self::boxed-text | self::table]) ]" | |
params="first-list-para" | |
mode="bits2hub-default" | |
line="457"/> | |
</stylesheet> | |
<stylesheet href="file:/C:/cygwin/home/gerrit/Hogrefe/BookTagSet/transpect/docxtools/hub2docx/xsl/module/merge-with-template.xsl" | |
count="1" | |
names="template-nums"> | |
<template match="w:num" | |
params="template-nums" | |
mode="hub:merge" | |
line="211"/> | |
</stylesheet> | |
<stylesheet href="file:/C:/cygwin/home/gerrit/Hogrefe/BookTagSet/transpect/schematron/oxy/iso-schematron-abstract.xsl" | |
count="4" | |
names="message params"> | |
<template match="* | processing-instruction() | comment()" | |
params="params" | |
mode="instantiate" | |
line="86"/> | |
<template match="@*" params="params" mode="instantiate" line="95"/> | |
<template match="*" params="message" mode="errorMsg" line="161"/> | |
<template match="text()" params="params" mode="instantiate" line="167"/> | |
</stylesheet> | |
<!-- … --> | |
</non-tunnel-params> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment