Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XSL - grab unprocessed nodes

XSL - grab unprocessed nodes

Scheduled Pinned Locked Moved XML / XSL
xml
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #1

    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

    B S P 3 Replies Last reply
    0
    • C Christian Graus

      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

      B Offline
      B Offline
      bart sawyer
      wrote on last edited by
      #2

      This is probably not what you are looking for, but i mention it anyway. bart <edit> Whoops, text was gone</edit>

      1 Reply Last reply
      0
      • C Christian Graus

        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

        S Offline
        S Offline
        Stuart Dootson
        wrote on last edited by
        #3

        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'

        1 Reply Last reply
        0
        • C Christian Graus

          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

          P Offline
          P Offline
          Paul Watson
          wrote on last edited by
          #4

          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 Africa

          Roger Wright wrote: Personally, I'm seeking a red-headed, double-breasted mattress thrasher

          C 1 Reply Last reply
          0
          • P Paul Watson

            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 Africa

            Roger Wright wrote: Personally, I'm seeking a red-headed, double-breasted mattress thrasher

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups