-
Notifications
You must be signed in to change notification settings - Fork 5
/
dereference.xsl
executable file
·50 lines (45 loc) · 1.72 KB
/
dereference.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns="http://www.xcede.org/xcede-2"
xmlns:xcede="http://www.xcede.org/xcede-2"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dyn="http://exslt.org/dynamic"
exclude-result-prefixes="xsl xcede"
version="1.0">
<xsl:variable name="apos">'</xsl:variable>
<xsl:output
method="xml"
indent="yes"
omit-xml-declaration="no"
/>
<xsl:template match="//xcede:subjectList/xcede:subjectRef|//xcede:visitList/xcede:visitRef|//xcede:studyList/xcede:studyRef|//xcede:episodeList/xcede:episodeRef|//xcede:acquisitionRef|//xcede:analysisRef|//xcede:dataResourceRef|//xcede:protocolTimeRef|//xcede:stepRef">
<xsl:variable name="url" select="substring-before(., '#xpointer(')"/>
<xsl:variable name="xpath" select="substring-before(substring-after(., '#xpointer('), ')')"/>
<xsl:choose>
<xsl:when test="string-length($url)=0">
<xsl:for-each select="dyn:evaluate($xpath)">
<xsl:copy>
<xsl:for-each select="@*|node()">
<xsl:apply-templates select="." />
</xsl:for-each>
</xsl:copy>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="evalstr" select="concat('document(',$apos,$url,$apos,',/)',$xpath)"/>
<xsl:for-each select="dyn:evaluate($evalstr)">
<xsl:copy>
<xsl:for-each select="@*|node()">
<xsl:apply-templates select="." />
</xsl:for-each>
</xsl:copy>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>