XSL - grab unprocessed nodes
-
I am writing an XSL to convert from our old to our new file format, and I want to get back a section showing me the nodes we've not processed. I've written this: The idea being that right now, all of the static section EXCEPT the id, filetype and date_contributed nodes should be in the remains sections. Any suggestions most welcome. Christian
-
I am writing an XSL to convert from our old to our new file format, and I want to get back a section showing me the nodes we've not processed. I've written this: The idea being that right now, all of the static section EXCEPT the id, filetype and date_contributed nodes should be in the remains sections. Any suggestions most welcome. Christian
This is probably not what you are looking for, but i mention it anyway. bart <edit> Whoops, text was gone</edit>
-
I am writing an XSL to convert from our old to our new file format, and I want to get back a section showing me the nodes we've not processed. I've written this: The idea being that right now, all of the static section EXCEPT the id, filetype and date_contributed nodes should be in the remains sections. Any suggestions most welcome. Christian
One possibility might be to use XMLdiff[^] to highlight deltas. Alternatively, you could investigate modes - you could process the node-set twice, once in a 'processing' mode, once in a 'not-processing' mode, using specific templates only for the nodes you want to process - consider this: test.xml
<section> <A>Text A</A> <A>Text A 2</A> <B>Text C</B> <C>Text C</C> <D>Text D</D> </section>
test.xslt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" extension-element-prefixes="redirect"> <xsl:template match="section"> <xsl:element name="test"> <xsl:element name="processed"> <xsl:apply-templates mode="normal"/> </xsl:element> <xsl:element name="not-processed"> <xsl:apply-templates mode="show-not-processed"/> </xsl:element> </xsl:element> </xsl:template> <xsl:template match="A" mode="normal"> <xsl:value-of select="name()"/> </xsl:template> <xsl:template match="C" mode="normal"> <xsl:value-of select="name()"/> </xsl:template> <xsl:template match="A|C" mode="show-not-processed"/> <xsl:template match="*" mode="normal"/> <xsl:template match="*" mode="show-not-processed"> <xsl:value-of select="name()"/> </xsl:template> </xsl:stylesheet >
test.out.xml (produced using Xalan 2.3.1 with test.xml as input and test.xslt as the stylesheet)
<?xml version="1.0" encoding="UTF-8"?> <test><processed> A A C </processed><not-processed> B D </not-processed></test>
The stylesheet uses the 'match-all' templates to mop up any nodes you don't mention explicitly in a template, so it's just a case of listing all the nodes you process in this template:
<xsl:template match="A|C" mode="show-not-processed"/>
HTH Stuart Dootson 'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
-
I am writing an XSL to convert from our old to our new file format, and I want to get back a section showing me the nodes we've not processed. I've written this: The idea being that right now, all of the static section EXCEPT the id, filetype and date_contributed nodes should be in the remains sections. Any suggestions most welcome. Christian
Hey CG, sorry for only replying now. Honestly I don't know the answer, I have not done much XSL of late as I am meeting stiff resistance to putting it into practical use. Knowing you though you will have figured it out by now, far better at this than I am.
Paul Watson
Bluegrass
Cape Town, South AfricaRoger Wright wrote: Personally, I'm seeking a red-headed, double-breasted mattress thrasher
-
Hey CG, sorry for only replying now. Honestly I don't know the answer, I have not done much XSL of late as I am meeting stiff resistance to putting it into practical use. Knowing you though you will have figured it out by now, far better at this than I am.
Paul Watson
Bluegrass
Cape Town, South AfricaRoger Wright wrote: Personally, I'm seeking a red-headed, double-breasted mattress thrasher
Hi Paul. What sort of resistance ? Why would people not want to use it ? Yes, in the end I wrote rules that specified the nodes I wanted and a rule that specified all other nodes, by listing the ones I wanted and put not in front of it. I was hoping for a sexier solution, but it eluded me. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder