Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL Transform - Why is it writing out everything?

Reply
Thread Tools

XSL Transform - Why is it writing out everything?

 
 
daz_oldham
Guest
Posts: n/a
 
      05-24-2006
Hi

I have done the folloing XSLT and although it does write out my
elements as I want, it is also writing out ALL of the information in
the child nodes and attributes as it loops around.

Any ideas would be greatly appreciated - I am sure it is something
tiny!

Best regards and many thanks

Darren

<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="http://www.someurl.com/abc/2002/09"
>


<xsl:template
match="ns1:ABC_AccomAvailRS/ns1:AccommodationSearchResponse/ns1:Accommodations">

This is the start of our XSLT Transformation.<br />

<xsl:for-each select="ns1:AccommodationSegment">

<div name="dvHotelName"
style="background-color:#0033FF;padding:2px">
<xsl:value-of select="@AccommodationName"/> - <xsl:value-of
select="@OfficialRating"/>

</div>

<xsl:apply-templates />
<b>
<xsl:value-of select="ns1escription"/>
</b>

</xsl:for-each>


<br />End of the XSLT Transformation

</xsl:template>

<xsl:template match="ns1:Image[1]">
<img src="{@ThumbnailURL}" />
</xsl:template>


</xsl:stylesheet>

 
Reply With Quote
 
 
 
 
daz_oldham
Guest
Posts: n/a
 
      05-24-2006
I have been able to put in additional templates as such:

<xsl:template match="ns1:Address" >

</xsl:template>

But I think that rather than solving the problem, this just hides it
doesn't it?

Thanks

Darren

 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      05-24-2006
daz_oldham wrote:
> I have done the folloing XSLT and although it does write out my
> elements as I want, it is also writing out ALL of the information in
> the child nodes and attributes as it loops around.


"All the information in the child nodes" doesn't surprise me a lot.
You're doing an apply-templates recursion with no select, which defaults
to processing all the children, and the default template for elements
dumps the text content of the element. So add a select= attribute to the
apply to tell it which ones you actually want to examine, and/or provide
templates that treat those other elements the way you want them treated.

I can't explain "and attributes" in this case, but I suspect that's an
erroneous report rather than an actual behavior.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      05-24-2006


daz_oldham wrote:


> I have done the folloing XSLT and although it does write out my
> elements as I want, it is also writing out ALL of the information in
> the child nodes and attributes as it loops around.



> <xsl:apply-templates />


You have not shown the input XML but if you do xsl:apply-templates then
that processes all child nodes (element nodes, text nodes, comment
nodes, processing instruction nodes) and as there are built-in default
templates (see
<http://www.w3.org/TR/xslt#built-in-rule>
) it is possible that for instance all text nodes are output.

So either do e.g.
<xsl:apply-templates select="someElement" />
meaning make sure that the above apply-templates applies only to the
element nodes you really want to be processed or make sure you override
the built-in templates e.g.
<xsl:template match="text()" />
so that for instance text nodes are not output.

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
daz_oldham
Guest
Posts: n/a
 
      05-24-2006
Spot on - thanks Martin, Joe for your help.

It is remembering these little obvious things that make a massive
difference - thanks

Darren

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
asp.net out of memory on transform why? Is there thread limit? Donald Adams ASP .Net 2 03-30-2007 07:19 AM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
blocking I/O with javax.xml.parsers.DocumentBuilder.parse() and javax.xml.transform.Transformer.transform() jazzdman@gmail.com Java 1 03-27-2005 06:56 AM
writing the result of xsl transform suzy ASP .Net 0 07-28-2003 10:47 AM



Advertisments