i having xml -
<a:price-range xmlns:c="http://iddn.icis.com/ns/core" xmlns:f="http://iddn.icis.com/ns/fields" xmlns:a="http://iddn.icis.com/ns/assets" xmlns:r="http://iddn.icis.com/ns/refdata"> <c:id> http://iddn.icis.com/series-item/petchem/4021090-pricehistory-19990730000000</c:id> <c:type>series-item</c:type> <f:assessment-low>8.946586935</f:assessment-low> <f:assessment-high>9.946586935</f:assessment-high> <f:mid>9.44658693500000000000</f:mid> <f:period-label> <c:l10n xml:lang="en"/> </f:period-label> </a:price-range>
i want normalise space in xml. in above example, there spaces in c:id element. after normalising spaces, above xml -
<a:price-range xmlns:c="http://iddn.icis.com/ns/core" xmlns:f="http://iddn.icis.com/ns/fields" xmlns:a="http://iddn.icis.com/ns/assets" xmlns:r="http://iddn.icis.com/ns/refdata"> <c:id>http://iddn.icis.com/series-item/petchem/4021090-pricehistory-19990730000000</c:id> <c:type>series-item</c:type> <f:assessment-low>8.946586935</f:assessment-low> <f:assessment-high>9.946586935</f:assessment-high> <f:mid>9.44658693500000000000</f:mid> <f:period-label> <c:l10n xml:lang="en"/> </f:period-label> </a:price-range>
i had @ fn:normalise-space, work strings only.
i don't think possible applying serialization options, have go through tree applying transformation pattern. adjusted example page normalize space , support namespaces:
declare function local:copy($node node()) node() { typeswitch($node) case $text text() return text { normalize-space($text) } case $element element() return element { qname(namespace-uri($element), name($element)) } { $element/@*, $child in $element/(* | text()) return local:copy($child) } default return $node }; local:copy( <a:price-range xmlns:c="http://iddn.icis.com/ns/core" xmlns:f="http://iddn.icis.com/ns/fields" xmlns:a="http://iddn.icis.com/ns/assets" xmlns:r="http://iddn.icis.com/ns/refdata"> <c:id> http://iddn.icis.com/series-item/petchem/4021090-pricehistory-19990730000000</c:id> <c:type>series-item</c:type> <f:assessment-low>8.946586935</f:assessment-low> <f:assessment-high>9.946586935</f:assessment-high> <f:mid>9.44658693500000000000</f:mid> <f:period-label> <c:l10n xml:lang="en"/> </f:period-label> </a:price-range> )
marklogic allows apply xslt stylesheet, might more elegant version of doing using <xsl:strip-space elements="*"/>
proposed @raj.