Changeset 25397
- Timestamp:
- 2012-04-17T16:24:48+12:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXSLT.java
r25389 r25397 39 39 Element main = main_xsl.getDocumentElement(); 40 40 41 NodeList children = extra_xsl.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "i nclude");41 NodeList children = extra_xsl.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "import"); 42 42 for (int i = 0; i < children.getLength(); i++) { 43 43 Node node = children.item(i); 44 // remove any previous occurrences of xsl:include with the same href value 45 removeDuplicateElementsFrom(main, node, "xsl:include", "href"); 46 main.appendChild(main_xsl.importNode(node, true)); 44 // If the new xsl:import element is identical (in terms of href attr value) 45 // to any in the merged document, don't copy it over 46 if(!isDuplicateElement(main, node, "xsl:import", "href")) { 47 // Import statements should be the first children of an xsl:stylesheet element 48 // If firstchild is null, then this xsl:import element will be inserted at the "end" 49 // Although Node.insertBefore() will first remove identical nodes before inserting, we check 50 // only the href attribute to see if they're "identical" to any pre-existing <xsl:import> 51 main.insertBefore(main_xsl.importNode(node, true), main.getFirstChild()); 52 } 47 53 } 48 49 children = extra_xsl.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "i mport");54 55 children = extra_xsl.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "include"); 50 56 for (int i = 0; i < children.getLength(); i++) { 51 57 Node node = children.item(i); 52 // remove any previous occurrences of xsl:output with the same method value 53 removeDuplicateElementsFrom(main, node, "xsl:import", "href"); 54 main.appendChild(main_xsl.importNode(node, true)); 58 // If the new xsl:include element is identical (in terms of href attr value) 59 // to any in the merged document, don't copy it over 60 // Although Node.appendChild() will first remove identical nodes before appending, we check 61 // only the href attribute to see if they're "identical" to any pre-existing <xsl:include> 62 if(!isDuplicateElement(main, node, "xsl:include", "href")) { 63 main.appendChild(main_xsl.importNode(node, true)); 64 } 55 65 } 56 66 … … 58 68 for (int i = 0; i < children.getLength(); i++) { 59 69 Node node = children.item(i); 60 // remove any previous occurrences of xsl:output with the same method value 61 removeDuplicateElementsFrom(main, node, "xsl:output", "method"); 62 main.appendChild(main_xsl.importNode(node, true)); 70 // If the new xsl:output element is identical (in terms of the value for the method attr) 71 // to any in the merged document, don't copy it over 72 if(!isDuplicateElement(main, node, "xsl:output", "method")) { 73 main.appendChild(main_xsl.importNode(node, true)); 74 } 63 75 } 64 76 … … 75 87 } 76 88 77 // In element main, tries to find if any previous occurrence of elements with template=templateName,89 // In element main, tries to find any previous occurrence of elements with xsl-template-name=templateName, 78 90 // and whose named attribute (attributeName) has the same value as the same attribute in node. 79 // If this is the case, such a previous occurrence is removed it from element main 91 // If this is the case, such a previous occurrence is removed from element main, since 92 // the new node will contain a more specific redefinition of this element. 80 93 public static void removeDuplicateElementsFrom(Element main, Node node, String templateName, String attrName) { 81 94 String attr = ((Element) node).getAttribute(attrName); … … 90 103 } 91 104 92 105 // Call this method on elements like xsl:include, xsl:import and xsl:output 106 // In element main, tries to find any previous occurrence of elements with xsl-element-name=xslName, 107 // and whose named attribute (attributeName) has the same value as the same attribute in node. 108 // If this is the case, it returns true, since the element would a complete duplicate for our intents. 109 public static boolean isDuplicateElement(Element main, Node node, String xslName, String attrName) { 110 String attr = ((Element) node).getAttribute(attrName); 111 if (!attr.equals("")) 112 { 113 Element old_element = GSXML.getNamedElement(main, xslName, attrName, attr); 114 if (old_element != null) 115 { 116 return true; 117 } 118 } 119 return false; 120 } 93 121 94 122 /**
Note:
See TracChangeset
for help on using the changeset viewer.