Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Basic XSLT question

Reply
Thread Tools

Basic XSLT question

 
 
Paul Smith
Guest
Posts: n/a
 
      08-11-2003
Apologies, I am new to XSLT. I am having trouble with something that I
would expect to be quite straightforward.

How do I leave XML tags as they are in a transformation? From the XML
below, I want to apply a stylesheet such that the XML is exactly the
same apart from the only <row> should be the first one from the XML
below. I can output some text for position()=1 but I can't output the
original XML too. So the only thing I get in my whole output document
is "Found it"!

Any help would be greatly appreciated.


Original XML:
<?xml version="1.0" encoding="UTF-8"?>
<xmlresults status="SDSUCCESS">
<tablemetadata>
<tablemetadataitem name="TABLE1" description="Table 1"/>
</tablemetadata>
<columnmetadata>
<columnmetadataitem name="COL1" description="Col 1" pos="2"/>
<columnmetadataitem name="COL2" description="Col 2" pos="1"/>
</columnmetadata>
<othertag>
<othertagitem name="Type" value="Something"/>
<othertagitem name="Direction" value="ASC"/>
</parameterdata>
<data>
<row>
<dataitem name="COL1" value="ABC"/>
<dataitem name="COL2" value="123"/>
</row>
<row>
<dataitem name="COL1" value="DEF"/>
<dataitem name="COL2" value="456"/>
</row>
</data>
</xmlresults>

Required Output from XSL transformation (note the second <row> is
missing):
<?xml version="1.0" encoding="UTF-8"?>
<xmlresults status="SDSUCCESS">
<tablemetadata>
<tablemetadataitem name="TABLE1" description="Table 1"/>
</tablemetadata>
<columnmetadata>
<columnmetadataitem name="COL1" description="Col 1" pos="2"/>
<columnmetadataitem name="COL2" description="Col 2" pos="1"/>
</columnmetadata>
<othertag>
<othertagitem name="Type" value="Something"/>
<othertagitem name="Direction" value="ASC"/>
</parameterdata>
<data>
<row>
<dataitem name="COL1" value="ABC"/>
<dataitem name="COL2" value="123"/>
</row>
</data>
</xmlresults>

My XSL (for what it's worth):
<?xml version="1.0"?>
<xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput method="html" indent="yes"/>

<xsl:template match="data">
<xsl:for-each select="row">
<xsl:choose>
<xsl:when test="position() = 1">
Found It
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      08-11-2003
In article <(E-Mail Removed) >,
Paul Smith <(E-Mail Removed)> wrote:

>How do I leave XML tags as they are in a transformation? From the XML
>below, I want to apply a stylesheet such that the XML is exactly the
>same apart from the only <row> should be the first one from the XML
>below.


You need a template that copies everything else. This will copy everything
that doesn't have a more specific template:

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

Your template for data will work, but it would be simpler to just have a
template for the non-first rows that does nothing:

<xsl:template match="row[position() > 1]">
</xsl:template>

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!
 
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
XSLT question: How to lookup another tag's children in XSLT yinglcs@gmail.com XML 18 10-03-2006 11:22 PM
ANN: New low-cost XML Editor, XSLT Editor, XSLT Debugger, DTD/Schema Editor Stylus Studio Java 0 08-03-2004 03:53 PM
Basic XSLT/XSLTC question Justine Hlista XML 3 03-04-2004 05:58 PM
[XSLT]Passing values from Javascript to a XSLT variable Benjamin Hillsley XML 3 09-25-2003 04:50 AM
Basic XSLT question - processing result tree? LW XML 1 09-18-2003 04:37 AM



Advertisments