I am new to XSLT, cant get my head around it. Need to transform the below input file to below output file, can someone help me with xslt code. thanks in advance. inputFile:
<input>
<inputOne>
<numberOne>1</numberOne>
</inputOne>
<inputTwo>
<numberTwo>2</numberTwo>
</inputTwo>
<inputThree>
<numberThree>3</numberThree>
</inputThree>
<inputFive>
<numberFive>5</numberFive>
</inputFive>
<inputFour>
<numberFour>4</numberFour>
</inputFour>
<inputThree>
<numberThree>32</numberThree>
</inputThree>
<inputFive>
<numberFive>52</numberFive>
</inputFive>
<inputFour>
<numberFour>42</numberFour>
</inputFour>
</input>
outputFile:
<input>
<inputOne>
<numberOne>1</numberOne>
<inputTwo>
<numberTwo>2</numberTwo>
<inputThree>
<numberThree>3</numberThree>
<inputFour>
<numberFour>4</numberFour>
<inputFive>
<numberFive>5</numberFive>
</inputFive>
</inputFour>
</inputThree>
<inputThree>
<numberThree>32</numberThree>
<inputFour>
<numberFour>42</numberFour>
<inputFive>
<numberFive>52</numberFive>
</inputFive>
</inputFour>
</inputThree>
</inputTwo>
</inputOne>
</input>
I am using Transformer object to transform streamsource into streamresult object. the transform object is created using xsl file.
my xsl file is not working.
xslcode:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8"/>
<xsl:template match="/input">
<xsl:copy>
<xsl:apply-templates select="inputOne"/>
</xsl:copy>
</xsl:template>
<xsl:template match="inputOne">
<xsl:apply-templates select="inputTwo"/>
</xsl:template>
<xsl:template match="inputOne[not(inputTwo)]">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="inputTwo">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
with above xsl i am trying to get inputOne tag and inside it inputTwo tag. but just getting the below:
<input>
<inputOne>
<numberOne>1</numberOne>
</inputOne>
</input>
appreciate any help to fix the xsl code. Thanks.
inputThreeis the parent of whichinputFouretc. I could understand it if each level would look only at its following siblings that do not have a closer preceding sibling at the same level. But you haveinputFivebeforeinputFour- and I don't know how to formulate a rule for that. - michael.hor257k