VirtualBox

source: vbox/trunk/src/libs/dita-ot-1.8.5/xsl/generalize.xsl@ 99443

Last change on this file since 99443 was 98584, checked in by vboxsync, 2 years ago

Docs: bugref:10302. Setting svn properties of DITA-OT library.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<!-- This file is part of the DITA Open Toolkit project hosted on
3 Sourceforge.net. See the accompanying license.txt file for
4 applicable licenses.-->
5<!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->
6
7<!-- generalize.xsl
8 | Convert specialied DITA topics into revertable, "generalized" form
9 *-->
10
11<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
12 xmlns:java="org.dita.dost.util.GenUtils" exclude-result-prefixes="java">
13 <xsl:param name="outdir.subsidiary"/>
14 <xsl:variable name="file-prefix">
15 <xsl:choose>
16 <xsl:when test="string-length($outdir.subsidiary) &gt; 0 and not(substring($outdir.subsidiary,string-length($outdir.subsidiary))='/')and not(substring($outdir.subsidiary,string-length($outdir.subsidiary))='\')">
17 <xsl:value-of select="translate($outdir.subsidiary,
18 '\/=+|?[]{}()!#$%^&amp;*__~`;:.,-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
19 '//=+|?[]{}()!#$%^&amp;*__~`;:.,-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')"/><xsl:text>/</xsl:text>
20 </xsl:when>
21 <xsl:otherwise>
22 <xsl:value-of select="translate($outdir.subsidiary,
23 '\/=+|?[]{}()!#$%^&amp;*__~`;:.,-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
24 '//=+|?[]{}()!#$%^&amp;*__~`;:.,-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
25 </xsl:otherwise>
26
27 </xsl:choose>
28 </xsl:variable>
29 <xsl:output method="xml" indent="no"/>
30
31 <xsl:template match="*[@class]">
32 <xsl:variable name="generalize" select="substring-before(substring-after(@class,'/'),' ')" />
33 <xsl:element name="{$generalize}">
34 <xsl:copy-of select="@*"/>
35 <xsl:apply-templates/>
36 </xsl:element>
37 </xsl:template>
38
39 <xsl:template match="*|@*|comment()|processing-instruction()|text()">
40 <xsl:copy>
41 <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/>
42 </xsl:copy>
43 </xsl:template>
44
45
46 <xsl:template match="*[contains(@class,' topic/unknown ') or contains(@class,' topic/foreign ')]" priority="10">
47 <xsl:variable name="spec-type">
48 <xsl:call-template name="get-spec-type"/>
49 </xsl:variable>
50 <xsl:variable name="generalize" select="substring-before(substring-after(@class,'/'),' ')"/>
51 <xsl:element name="{$generalize}">
52 <xsl:apply-templates select="*|@*|text()|comment()|processing-instruction()" mode="generalize-foreign-unknown">
53 <xsl:with-param name="spec-type" select="$spec-type"/>
54 </xsl:apply-templates>
55 </xsl:element>
56 </xsl:template>
57
58 <xsl:template match="*[contains(@class,' topic/object ')]|@*|text()|comment()|processing-instruction()" mode="generalize-foreign-unknown">
59 <xsl:copy>
60 <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/>
61 </xsl:copy>
62 </xsl:template>
63
64 <xsl:template match="*[not(contains(@class,' topic/object '))]" mode="generalize-foreign-unknown">
65 <xsl:param name="spec-type"/>
66 <xsl:value-of select="preceding-sibling::*[not(contains(@class,' topic/topic '))]"/>
67
68 <!-- find out the subsidiary result file name that need to be generated. -->
69 <xsl:variable name="filename">
70 <xsl:text>dita-generalized-</xsl:text>
71 <xsl:value-of select="ancestor::*[contains(@class,' topic/topic ')][1]/@id"/>
72 <xsl:text>-</xsl:text>
73 <xsl:value-of select="concat($spec-type,generate-id(.))"/>
74 <xsl:text>.xml</xsl:text>
75 </xsl:variable>
76
77 <xsl:element name="object">
78 <xsl:attribute name="data">
79 <xsl:value-of select="$filename"/>
80 </xsl:attribute>
81 <xsl:attribute name="type">
82 <xsl:text>DITA-foreign</xsl:text>
83 </xsl:attribute>
84 </xsl:element>
85 <xsl:variable name="generalize" select="substring-before(substring-after(../@class,'/'),' ')"></xsl:variable>
86 <xsl:value-of select="java:clear()"/>
87 <xsl:value-of select="java:setOutput(concat($file-prefix,$filename))"/>
88 <xsl:value-of select="java:startElement($generalize)"/>
89 <xsl:value-of select="java:addAttr('class',string(../@class))"/>
90 <xsl:apply-templates select="." mode="generalize-subsidiary"/>
91 <xsl:value-of select="java:endElement($generalize)"/>
92 <xsl:value-of select="java:flush()"/>
93 </xsl:template>
94
95 <xsl:template match="*" mode="generalize-subsidiary">
96 <xsl:variable name="name" select="name()"/>
97 <xsl:value-of select="java:startElement($name)"/>
98 <xsl:apply-templates select="*|@*|text()|comment()" mode="generalize-subsidiary"/>
99 <xsl:value-of select="java:endElement($name)"/>
100 </xsl:template>
101
102 <xsl:template match="@*" mode="generalize-subsidiary">
103 <xsl:variable name="name" select="name()"/>
104 <xsl:variable name="value"><xsl:value-of select="."/></xsl:variable>
105 <xsl:value-of select="java:addAttr($name,$value)"/>
106 </xsl:template>
107
108 <xsl:template match="text()|comment()" mode="generalize-subsidiary">
109 <xsl:variable name="text"><xsl:value-of select="."/></xsl:variable>
110 <xsl:value-of select="java:addText($text)"/>
111 </xsl:template>
112
113 <xsl:template name="get-spec-type">
114 <xsl:param name="class" select="substring-after(@class,' ')"/>
115 <xsl:choose>
116 <xsl:when test="contains(substring-after($class,'/'),'/')">
117 <xsl:call-template name="get-spec-type">
118 <xsl:with-param name="class" select="substring-after($class,' ')"/>
119 </xsl:call-template>
120 </xsl:when>
121 <xsl:otherwise>
122 <xsl:value-of select="substring-before($class,'/')"/>
123 </xsl:otherwise>
124 </xsl:choose>
125 </xsl:template>
126</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette