This has the added benefit of not requiring the whitespace-processing step in the article, and could be easily modified to select elements based on attributes (e.g., language). However, it does require that the sitemap document actually be well-formed XML – the example in the article is not well-formed because it contains an unclosed <urlset> element. This is why XML parsers, validating parsers and transformers are so much more valuable than ad-hoc implementations. If the document does not conform to the specification, it will tell you.
You can also transform via the xsltc library, Java or C# DOM or one of many other XML DOM-compliant transformers if you need to integrate into an existing codebase.
ZALGO RISES FROM THE DEPTHS!
Alternatively, here is an equivalent XSL stylesheet that can be applied directly to a sitemap XML document:
This has the added benefit of not requiring the whitespace-processing step in the article, and could be easily modified to select elements based on attributes (e.g., language). However, it does require that the sitemap document actually be well-formed XML – the example in the article is not well-formed because it contains an unclosed
<urlset>element. This is why XML parsers, validating parsers and transformers are so much more valuable than ad-hoc implementations. If the document does not conform to the specification, it will tell you.So how would I run this under a flavor of Linux?
You can use xsltproc (pre-installed or available via a package manager with many Linux distributions):
You can also transform via the
xsltclibrary, Java or C# DOM or one of many other XML DOM-compliant transformers if you need to integrate into an existing codebase.