comparison software/eXist/webapp/mpdl/presentation/insertExternalElements.xsl @ 9:1ec29fdd0db8

neue .lex Dateien f?r Normalisierung / externe Objekte update
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 22 Feb 2011 16:03:45 +0100
parents
children 469d927b9ca7
comparison
equal deleted inserted replaced
8:d2a1c14fde31 9:1ec29fdd0db8
1 <?xml version="1.0"?>
2 <xsl:stylesheet version="2.0"
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:xs="http://www.w3.org/2001/XMLSchema"
5 xmlns:saxon="http://saxon.sf.net/"
6 xmlns:text="http://www.mpiwg-berlin.mpg.de/ns/mpdl/text"
7 xmlns:mpdlxmlutil="java:de.mpg.mpiwg.berlin.mpdl.util.XmlUtil"
8 >
9
10 <xsl:output method="xml" encoding="utf-8"/>
11 <xsl:output name="myXml" indent="yes" omit-xml-declaration="yes"/>
12
13 <xsl:variable name="externalElements" select="/result/externalElements"/>
14 <xsl:variable name="fragment" select="/result/fragment"/>
15
16 <xsl:template match="result">
17 <xsl:apply-templates/>
18 </xsl:template>
19 <xsl:template match="fragment">
20 <xsl:apply-templates/>
21 </xsl:template>
22 <xsl:template match="externalElements">
23 </xsl:template>
24
25 <xsl:template match="attribute()|text()|comment()|processing-instruction()">
26 <xsl:copy>
27 <xsl:apply-templates select="attribute()|element()|text()|comment()|processing-instruction()"/>
28 </xsl:copy>
29 </xsl:template>
30
31 <xsl:template match="element()">
32 <xsl:variable name="elemXmlNodeIdTmp" select="saxon:path(.)"/>
33 <xsl:variable name="elemXmlNodeId" select="concat('/', substring-after(substring-after(substring-after($elemXmlNodeIdTmp, '/'), '/'), '/'))"/>
34 <xsl:variable name="extElemXmlNodeIds" select="$externalElements//@xmlNodeId"/>
35 <xsl:variable name="extElemIndex" select="index-of($extElemXmlNodeIds, $elemXmlNodeId)"/>
36 <xsl:variable name="extElem" select="$externalElements/*[$extElemIndex]"/>
37 <xsl:variable name="extElemContent" select="$extElem/content/*[1]"/>
38 <xsl:variable name="extElemContentSerialized" select="saxon:serialize($extElemContent, 'myXml')"/>
39 <xsl:variable name="before">
40 <xsl:choose>
41 <xsl:when test="empty($extElem/@before) or $extElem/@before = ''">
42 <xsl:value-of select="''"/>
43 </xsl:when>
44 <xsl:otherwise>
45 <xsl:value-of select="string($extElem/@before)"/>
46 </xsl:otherwise>
47 </xsl:choose>
48 </xsl:variable>
49 <xsl:variable name="charPos">
50 <xsl:choose>
51 <xsl:when test="empty($extElem/@charPos) or $extElem/@charPos = ''">
52 <xsl:value-of select="xs:integer(-1)"/>
53 </xsl:when>
54 <xsl:otherwise>
55 <xsl:sequence select="xs:integer($extElem/@charPos)"/>
56 </xsl:otherwise>
57 </xsl:choose>
58 </xsl:variable>
59 <xsl:variable name="elemSerialized" select="saxon:serialize(., 'myXml')"/>
60 <xsl:variable name="insertedElemSerialized" select="mpdlxmlutil:insertAtCharPos(mpdlxmlutil:new(), $elemSerialized, string($charPos), $extElemContentSerialized)"/>
61 <xsl:variable name="insertedElemDeSerializedTmp" select="saxon:parse($insertedElemSerialized)"/>
62 <xsl:variable name="insertedElemDeSerialized">
63 <xsl:element name="{name()}">
64 <xsl:apply-templates select="attribute()"/>
65 <xsl:attribute name="xmlNodeId">
66 <xsl:value-of select="$elemXmlNodeId"/>
67 </xsl:attribute>
68 <xsl:sequence select="$insertedElemDeSerializedTmp/*[1]/node()"/>
69 </xsl:element>
70 </xsl:variable>
71 <xsl:if test="$charPos &lt; 0 and $before = 'true'">
72 <xsl:sequence select="$extElemContent"/>
73 </xsl:if>
74 <xsl:if test="$charPos &gt;= 0">
75 <xsl:sequence select="$insertedElemDeSerialized"/>
76 </xsl:if>
77 <xsl:if test="$charPos &lt; 0">
78 <xsl:copy>
79 <xsl:apply-templates select="attribute()"/>
80 <xsl:attribute name="xmlNodeId">
81 <xsl:value-of select="$elemXmlNodeId"/>
82 </xsl:attribute>
83 <xsl:apply-templates select="element()|text()|comment()|processing-instruction()"/>
84 </xsl:copy>
85 </xsl:if>
86 <xsl:if test="$charPos &lt; 0 and $before = 'false'">
87 <xsl:sequence select="$extElemContent"/>
88 </xsl:if>
89 </xsl:template>
90
91 </xsl:stylesheet>