xml - To Substring in xsl -


hi converting 1 xml xml using xsl.

the problem face value inside tag 10feb2011 i.e <date>10feb2011</date>.

i need output be:

 <date>10</date>  <month>feb</month>  <year>2011</year>  

so used substring function, not work.

my xml looks like

<arrivaldatetime>   <date>20feb2011<date> </arrivaldatetime> 

it should converted format

 <arrivaldatetime>    <dayofmonth>10</dayofmonth>     <month>feb</month>     <year>2011</year>   </arrivaldatetime> 

below xsl wrote

<?xml version="1.0" encoding="iso-8859-1"?> <!-- edited xmlspy® --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/">         <xsl:text><![cdata[<arrivaldatetime>]]></xsl:text>           <xsl:text><![cdata[<dayofmonth>]]></xsl:text> <xsl:value-of select='substring("<xsl:value-of select="/arrivaldatetime/date"/>",1,2)'/> <xsl:text><![cdata[</dayofmonth>]]></xsl:text> <xsl:text><![cdata[<month>]]></xsl:text> <xsl:value-of select='substring("<xsl:value-of select="/arrivaldatetime/date"/>",3,3)'/> <xsl:text><![cdata[</month>]]></xsl:text> <xsl:text><![cdata[<year>]]></xsl:text> <xsl:value-of select='substring("<xsl:value-of select="/arrivaldatetime/date"/>",5,4)'/> <xsl:text><![cdata[</year>]]></xsl:text> <xsl:text><![cdata[</arrivaldatetime>]]></xsl:text></xsl:template> </xsl:stylesheet> 

your xslt looks overly complicated. create xml nodes that:

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">   <xsl:output method="xml" indent="yes"/>    <xsl:template match="/">     <arrivaldatetime>       <dayofmonth>         <xsl:value-of select="substring(/arrivaldatetime/date,1,2)"/>       </dayofmonth>       <month>         <xsl:value-of select="substring(/arrivaldatetime/date,3,3)"/>       </month>       <year>         <xsl:value-of select="substring(/arrivaldatetime/date,5,4)"/>       </year>     </arrivaldatetime>   </xsl:template> </xsl:stylesheet> 

you shouldn't using cdata sections create xml nodes in output document. unnecessary , potentially dangerous allows generation of invalid xml.

please note inside xpath expressions such within select attributes must write valid xpath. xml tags not allowed here.

best check xslt tutorial started.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -