Transforming XML by means of XSLT — how to remove tags totally? -


at moment, working xslt & need help. have xml file:

<?xml version="1.0" encoding="utf-8" standalone="no"?> <entries>     <entry>         <field>1</field>     </entry>     <entry>         <field>2</field>     </entry>     <entry>         <field>3</field>     </entry>     <entry>         <field>4</field>     </entry>     <entry>         <field>5</field>     </entry> </entries> 

i need format xml reseive this:

<?xml version="1.0" encoding="utf-8" standalone="no"?> <entries>     <entry field="1">     <entry field="2">     <entry field="3">     <entry field="4">     <entry field="5"> </entries> 

but reseive this:

<?xml version="1.0" encoding="utf-8" standalone="no"?><entries>          <entry field="1">           <entry field="2">           <entry field="3">           <entry field="4">           <entry field="5">  </entries> 

xslt-file:

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="3.0">     <xsl:output method="xml" indent="no" encoding="utf-8" standalone="no"/>     <xsl:template match="entries">         <entries>             <xsl:apply-templates/>         </entries>     </xsl:template>     <xsl:template match="entry">             <xsl:apply-templates/>     </xsl:template>     <xsl:template match="field">         <xsl:text disable-output-escaping="yes">&lt;entry field="</xsl:text><xsl:apply-templates/><xsl:text disable-output-escaping="yes">"&gt;</xsl:text>     </xsl:template> </xsl:stylesheet> 

as see, xslt-stylesheet deletes tags, without removing them, leaving space. how remove tags <entry> totally & move first <entries> tag next line? otherwise, how make xml desired form?

if must output ill-formed xml (i.e. not xml document @ all), suggest use text output method , format indents yourself:

xslt 1.0

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="text"/> <xsl:strip-space elements="*"/>  <xsl:template match="entries">     <xsl:text>&lt;entries></xsl:text>         <xsl:apply-templates/>     <xsl:text>&#10;&lt;/entries></xsl:text> </xsl:template>  <xsl:template match="entry">     <xsl:text>&#10;    &lt;entry field="</xsl:text>     <xsl:value-of select="field"/>     <xsl:text>"></xsl:text> </xsl:template>  </xsl:stylesheet> 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -