xslt - XSL apply-templates output issues -


given xml:

<?xml version="1.0" encoding="iso-8859-2" ?>     <products>         <p>             <id> 50 </id>             <name> murphy </name>             <price> 33 </price>         </p>         <p>             <id> 40 </id>             <name> eddie </name>             <price> 9999 </price>         </p>         <p>             <id> 20 </id>             <name> honey </name>             <price> 9999 </price>         </p>         <p>             <id> 30 </id>             <name> koney </name>             <price> 11 </price>         </p>         <p>             <id> 10 </id>             <name> margarethe </name>             <price> 11 </price>         </p>     </products> 

with xsl:

<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">  <xsl:template match="p[id &gt; 20]">     <idkp>   <xsl:value-of select="id"/></idkp>     <skitter><xsl:value-of select="name"/></skitter> </xsl:template>   <xsl:template match="/">     <xsl:apply-templates/> </xsl:template> </xsl:stylesheet> 

having output:

<?xml version="1.0"?> <idkp>50</idkp><skitter>murphy</skitter> <idkp>40</idkp><skitter>eddie</skitter> 20 honey 9999 <idkp>30</idkp><skitter>koney</skitter> 10 margarethe 11 

q : why there values of did not matched? 20, honey, 9999, ...

because of built-in template rules - when there no explicit templates match particular node, built-in rules used, element nodes means <xsl:apply-templates/> , text nodes means <xsl:value-of select="."/>. effect of these 2 rules in combination output text under elements not element tags themselves.

you add second do-nothing template

<xsl:template match="p" /> 

to ignore p elements don't match condition. explicit template, do-nothing one, preferred on default built-in rule.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -