Changeset 25913
- Timestamp:
- 2012-07-10T10:22:25+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXSLT.java
r25847 r25913 44 44 * named templates overwrite any existing one, while match templates are 45 45 * just added to the end of the stylesheet 46 47 * elements are added in following order, and added to preserve original order with imported ones coming after existing ones 48 * import, include, output, variable, template 46 * 47 * elements are added in following order, and added to preserve original 48 * order with imported ones coming after existing ones import, include, 49 * output, variable, template 49 50 */ 50 51 public static void mergeStylesheetsDebug(Document main_xsl, Element extra_xsl, boolean overwrite, boolean debug, String firstDocFileName, String secondDocFileName) … … 58 59 Element main = main_xsl.getDocumentElement(); 59 60 Node insertion_point = null; 60 Element last_import = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "import"); 61 if (last_import != null) { 62 insertion_point = last_import.getNextSibling(); 63 } else { 64 insertion_point = main.getFirstChild(); 65 } 66 61 Element last_import = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "import"); 62 if (last_import != null) 63 { 64 insertion_point = last_import.getNextSibling(); 65 } 66 else 67 { 68 insertion_point = main.getFirstChild(); 69 } 70 67 71 // imports 68 72 NodeList children = extra_xsl.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "import"); 69 73 for (int i = 0; i < children.getLength(); i++) 70 74 { 71 75 Element node = (Element) children.item(i); 72 76 // If the new xsl:import element is identical (in terms of href attr value) 73 77 // to any in the merged document, don't copy it over … … 79 83 // only the href attribute to see if they're "identical" to any pre-existing <xsl:import> 80 84 //main.insertBefore(main_xsl.importNode(node, true), main.getFirstChild()); 81 main.insertBefore(main_xsl.importNode(node, true), insertion_point); 82 83 } 84 } 85 86 // do we have a new insertion point?? 87 Element last_include = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "include"); 88 if (last_include != null) { 89 insertion_point = last_include.getNextSibling(); 90 } 91 85 main.insertBefore(main_xsl.importNode(node, true), insertion_point); 86 87 } 88 } 89 90 // do we have a new insertion point?? 91 Element last_include = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "include"); 92 if (last_include != null) 93 { 94 insertion_point = last_include.getNextSibling(); 95 } 96 92 97 // includes 93 98 children = extra_xsl.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "include"); 94 99 for (int i = 0; i < children.getLength(); i++) 95 100 { 96 Element node = (Element)children.item(i);101 Element node = (Element) children.item(i); 97 102 // If the new xsl:include element is identical (in terms of href attr value) 98 103 // to any in the merged document, don't copy it over 99 104 // Although Node.appendChild() will first remove identical nodes before appending, we check 100 105 // only the href attribute to see if they're "identical" to any pre-existing <xsl:include> 101 if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "include", "href", node.getAttribute("href")) ==null)102 { 103 104 106 if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "include", "href", node.getAttribute("href")) == null) 107 { 108 //main.appendChild(main_xsl.importNode(node, true)); 109 main.insertBefore(main_xsl.importNode(node, true), insertion_point); 105 110 } 106 111 } // for each include 107 108 // do we have a new insertion point?? 109 Element last_output = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "output"); 110 if (last_output != null) { 111 insertion_point = last_output.getNextSibling(); 112 } 112 113 // do we have a new insertion point?? 114 Element last_output = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "output"); 115 if (last_output != null) 116 { 117 insertion_point = last_output.getNextSibling(); 118 } 113 119 114 120 // outputs … … 116 122 for (int i = 0; i < children.getLength(); i++) 117 123 { 118 Element node = (Element)children.item(i);124 Element node = (Element) children.item(i); 119 125 // If the new xsl:output element is identical (in terms of the value for the method attr) 120 126 // to any in the merged document, don't copy it over 121 if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "output", "method", node.getAttribute("method")) ==null)127 if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "output", "method", node.getAttribute("method")) == null) 122 128 { 123 129 main.insertBefore(main_xsl.importNode(node, true), insertion_point); … … 130 136 for (int i = 0; i < children.getLength(); i++) 131 137 { 132 Element node = (Element)children.item(i);138 Element node = (Element) children.item(i); 133 139 // If the new xsl:import element is identical (in terms of href attr value) 134 140 // to any in the merged document, don't copy it over 135 if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "variable", "name", node.getAttribute("name"))==null)141 if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "variable", "name", node.getAttribute("name")) == null) 136 142 { 137 143 main.appendChild(main_xsl.importNode(node, true)); … … 144 150 for (int i = 0; i < children.getLength(); i++) 145 151 { 146 152 Element node = (Element) children.item(i); 147 153 // remove any previous occurrences of xsl:template with the same value for name or match 148 149 154 String template_match = node.getAttribute("match"); 155 String template_name = node.getAttribute("name"); 150 156 151 157 if (overwrite) 152 158 { 153 // if we have a name attribute, remove any other similarly named template 154 if (!template_name.equals("")) { 155 GSXML.removeNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "template", "name", template_name); 156 } 157 // if we have a match attribute, remove other templates that match - 158 if (!template_match.equals("")) { 159 GSXML.removeNamedElementsNS(main, "http://www.w3.org/1999/XSL/Transform", "template", "match", template_match); 160 } 161 // now add our good template in 162 main.appendChild(main_xsl.importNode(node, true)); 163 } 164 else 165 { 166 // if overwrite is false, then we only add in templates if they don't match something else. 167 // In this case (eg from expanding imported stylesheets) 168 // there can't be any duplicate named templates, so just look for matches 169 // we already have the one with highest import precedence (from the top most level) so don't add any more in 170 if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform","template", "match", template_match) == null) 171 { 159 // if we have a name attribute, remove any other similarly named template 160 if (!template_name.equals("")) 161 { 162 GSXML.removeNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "template", "name", template_name); 163 } 164 // if we have a match attribute, remove other templates that match - 165 if (!template_match.equals("")) 166 { 167 GSXML.removeNamedElementsNS(main, "http://www.w3.org/1999/XSL/Transform", "template", "match", template_match); 168 } 169 // now add our good template in 172 170 main.appendChild(main_xsl.importNode(node, true)); 173 171 } 174 } 172 else 173 { 174 // if overwrite is false, then we only add in templates if they don't match something else. 175 // In this case (eg from expanding imported stylesheets) 176 // there can't be any duplicate named templates, so just look for matches 177 // we already have the one with highest import precedence (from the top most level) so don't add any more in 178 if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "template", "match", template_match) == null) 179 { 180 main.appendChild(main_xsl.importNode(node, true)); 181 } 182 } 175 183 } 176 184 … … 312 320 } 313 321 } 314 315 316 317 322 318 323 /**
Note:
See TracChangeset
for help on using the changeset viewer.