I have a javascript file that looks like this:
if (x > 0 && x < 100) {
$('#thing').append('<foo id="foo' + x + '">' + stuff + '</foo>');
}
And an xsl stylesheet that looks like this:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="foo">
<div>
<xsl:copy-of select="@*"/>
<xsl:value-of select="."/>
</div>
</xsl:template>
</xsl:stylesheet>
I want to be able to apply that template and possibly other ones to the xml contained in the javascript file.
In this case, the output should look like this:
if (x > 0 && x < 100) {
$('#thing').append('<div id="foo' + x + '">' + stuff + '</div>');
}
I will use the following constraints on the javascript file if it makes it easier to parse:
- I will never use &, <, or > inside or between the XML tags.
- I will never use nested XML tags.
- I will only use double quotes (") in or around the XML tags to set the element attributes.
- I will always have one or more spaces surrounding each < or > character in the regular javascript parts of the text.
I might be able to make other constraints as necessary.
I am using Saxon, so I can use XSLT 2.0 functions and saxon extensions.