Here is the problem:
I'm looping over a set of nodes and based on their type i'd like to use the jQuery xslt plugin.
var options = {
type: "POST",
url: "api/dosomething/usefull",
data: "orderid=12345",
success: function(response) {
$(response).find("group").each(function() {
if ($(this).attr(type) == "X") {
$.xslt({xml: $(this), xslUrl: 'xsl/order/x_group.xsl', xslCache: false, callback: function(data){
//do something usefull with the transformed data
}});
} else {
$.xslt({xml: $(this), xslUrl: 'xsl/order/other_group.xsl', xslCache: false, callback: function(data){
//do else with the transformed data
}});
}
})
}
};
The problem is that the the xslt plugin expects a javascript document object. How can I transform the result of the each function back into a document? $(this).text() will strip all inner xml tags. $(this).html() won't work either, since XML under jQuery doesn't support that. Plainly using this as parameter (ofcourse) triggers an error.
Alternatives considerd:
- Using the javascript inbuilt document parsing functions to reduce the document to the nodes we need and then throw hem through the xslt parser. Given the ease of use of jQuery, i'd rather not do that though.
- Throw the whole document into the xslt parser and solve it in the xslt. This would be an option, if the parser (or the xslt parser from the browser we're targeting instead of the pluign) would support xsl:import. We need to reuse these xslt's
- I could create a new document, if only i knew how to get the internal string representation...