java - Camel: xsl transformation doesn't indent xml -


i have started use camel spring boot , xsl new project. have following example:

students.xml

<?xml version="1.0" encoding="utf-8"?> <class>    <student rollno="393">       <firstname>dinkar</firstname>       <lastname>kad</lastname>       <nickname>dinkar</nickname>       <marks>85</marks>    </student>    <student rollno="493">       <firstname>vaneet</firstname>       <lastname>gupta</lastname>       <nickname>vinni</nickname>       <marks>95</marks>    </student>    <student rollno="593">       <firstname>jasvir</firstname>       <lastname>singh</lastname>       <nickname>jazz</nickname>       <marks>90</marks>    </student> </class> 

which transformed following xsl(ignore comments;new xsl):

students.xsl

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform"     version="1.0">     <xsl:output method="xml" indent="yes" />      <xsl:template match="*"><!-- matches node -->         <xsl:copy><!-- copies current node , namespace nodes,not child or attribute nodes -->             <xsl:apply-templates select="student" /><!-- applies template students elements -->         </xsl:copy>     </xsl:template>      <xsl:template match="student">         <xsl:element name="person"><!-- renames element person -->             <xsl:attribute name="id-num"><!--  applies attribute new element called id-num -->                 <xsl:value-of select="@rollno" /><!-- copies value of student eles rollno attribute -->             </xsl:attribute>             <xsl:apply-templates select="lastname" /><!-- applies template lastname child nodes -->             <xsl:apply-templates select="marks" /><!-- applies template marks child nodes -->         </xsl:element>     </xsl:template>      <xsl:template match="lastname">         <xsl:element name="student-surname">             <xsl:attribute name="nick-name">                  <xsl:value-of select="../nickname" /><!-- moves level in xml tree , copies value nickname element -->             </xsl:attribute>             <xsl:value-of select="." /><!-- copies text value of current node -->         </xsl:element>     </xsl:template>      <xsl:template match="marks">         <xsl:element name="grade">             <xsl:value-of select="." />         </xsl:element>     </xsl:template> </xsl:stylesheet> 

im performing transformation via camel. route configuration follows(camel spring boot starter, version 2.17.3):

samplecamelrouter.java

@component public class samplecamelrouter extends routebuilder {      /* (non-javadoc)      * @see org.apache.camel.builder.routebuilder#configure()      */     @override     public void configure() throws exception {         // todo auto-generated method stub         from("file:src/main/resources/input/?filename=students.xml&noop=true")             .to("xslt:./transforms/students.xsl")             .to("file:target/messages/?filename=studentsout.xml");     }  } 

whenever run application, transform happens regards creating new elements, stripping out others, copying values etc,. doesn't indent despite xsl:output line near beginning of file. have tried adding xsl:strip-space tag in previous run , didn't affect output. when run transform:

students-output.xml

<?xml version="1.0" encoding="utf-8"?><class> <person id-num="393"> <student-surname nick-name="dinkar">kad</student-surname> <grade>85</grade> </person> <person id-num="493"> <student-surname nick-name="vinni">gupta</student-surname> <grade>95</grade> </person> <person id-num="593"> <student-surname nick-name="jazz">singh</student-surname> <grade>90</grade> </person> </class> 

is there i'm missing? template interfering indentation?

try changing:

<xsl:output method="xml" indent="yes" /> 

to:

<xsl:output method="xml" indent="yes" xalan:indent-amount="2" xmlns:xalan="http://xml.apache.org/xalan"/> 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -