0

I have an input XML file which looks like this:

<Root>
 <Monday>Monday<Monday>
 <Indicator>true<Indicator>
 <Value>1<Value>
 <Tuesday>Tuesday<Tuesday>
 <Indicator>true<Indicator>
 <Value>2<Value>
 <Wednesday>Wednesday<Wednesday>
 <Indicator>true<Indicator>
 <Value>3<Value>
</Root>

It must be converted to the output XML file which is:

<Root>
 <Monday>Monday<Monday>
 <Value>1<Value>
 <Tuesday>Tuesday<Tuesday>
 <Value>2<Value>
 <Wednesday>Wednesday<Wednesday>
 <Value>3<Value>
</Root>

The problem is that the input XML can vary. Sometimes it might be

<Root>
 <Monday>Monday<Monday>
 <Indicator>true<Indicator>
 <Value>1<Value>
 <Thursday>Thursday<Thursday>
 <Indicator>true<Indicator>
 <Value>4<Value>
</Root>

Now the output must be

<Root>
 <Monday>Monday<Monday>
 <Value>1<Value>
 <Thursday>Thursday<Thursday>
 <Value>4<Value>
</Root>

I also have the list of valid tags like Monday, Tuesday etc, which can come in the input XML in an ArrayList in Java. Any ideas on how to accomplish this?

msrd0
  • 7,816
  • 9
  • 47
  • 82
AbilP
  • 1
  • 1
  • 1
    The question is not clear. Where do you get you input from? Where do you want to output? The only thing you are doing, as far as I can understand is that you want to remove the `Indicator` tag – Alkis Kalogeris Aug 24 '14 at 11:49
  • The order of day, indicator, value is fixed? Also, have you tried anything yourself? If not, why not? If yes, show your attempt. – Tomalak Aug 24 '14 at 11:49

1 Answers1

1

From this answer: How to remove elements from xml using xslt with stylesheet and xsltproc? :

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output omit-xml-declaration="yes"/>

    <xsl:template match="node()|@*">
       <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
       </xsl:copy>
    </xsl:template>

    <xsl:template match="Indicator"/>
</xsl:stylesheet>
Community
  • 1
  • 1
Marcin Szawurski
  • 1,313
  • 12
  • 15