• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XSLT Transformation error

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi i am applying a sample XSLT to xml file.but upon applying xslt
i am getting every node results rather than intended xpath expression
node values.

xml file :
<response>
<objectset>
<document>
..
.. some elements
<properties>
<property>
<name>a</name>
</property>
<property>
<name>b</name>
</property>
</properties>
</document>

<document> --2nd doc element
..
.. some elements
<properties>
<property>
<name>a</name>
</property>
<property>
<name>b</name>
</property>
</properties>
</document>

<document> -- 3rd document element
..
.. some elements
<properties>
<property>
<name>a</name>
</property>
<property>
<name>b</name>
</property>
</properties>
</document>
</objectset>
</response>

xslt File :

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:java="http://xml.apache.org/xslt/java">
<xsl:output method="html" omit-xml-declaration="yes" indent="yes" />
<xsl:template atch="/response/objectset">
<xsl:for-each select="document">
<xsl:for-each select="properties/property">
<xsl:value-of select="name"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

please correct this xsl file ...?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
XSLT has a set of processing rules that it follows when it transforms a document. Specifically they work like this:

Start at the root element and process the template that applies to it. If there is no template specified, then do the default processing.

Default processing for text nodes is to copy the text to the output. (This is what you are seeing, it sounds like.)

Default processing for element nodes is to process the template that applies to it, if there is one, or to process all the child nodes.

So if you use a transformation with no templates at all, the output is all of the text nodes in the source document.

If you don't want default processing to take place, then provide a template that applies to the root node. Inside that template you should apply the templates you actually want run.
 
chinna talluru
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your concept Mr.Paul.
i rectified myself regarding template processing.

so that i modified according template rule as follows :

NEW xsLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:java="http://xml.apache.org/xslt/java">
<xsl:output method="html" omit-xml-declaration="yes" indent="yes" />

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="objectset">

<xsl:for-each select="document">
<xsl:apply-templates select="properties"/>
</xsl:for-each>

</xsl:template>

<xsl:template match="properties">
<xsl:for-each select="property">
<xsl:apply-templates/>

</xsl:for-each>
</xsl:template>
<xsl:template match="property">
<xsl:value-of select="name"/>
</xsl:template>
</xsl:stylesheet>

but now from properties onwards i am getting all content.i think default behaviour is applying for properties node.but i used a template for property
and i called this template from properties template.

will any please rectify me..
 
reply
    Bookmark Topic Watch Topic
  • New Topic