473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Basic XSLT question

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 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output 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>
Jul 20 '05 #1
1 1557
In article <2b**************************@posting.google.com >,
Paul Smith <pd*****@yahoo.co.uk> 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!
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: LW | last post by:
I'm using the following free implementation of an XSLT "split" function, as a template: http://www.exslt.org/str/functions/split/str.split.template.xsl.html Basically, it allows me to call it...
9
by: Tom | last post by:
Hey all, I've been planning to get myself started with DocBook for quite some time now, so when I unexpectedly encountered a task for which DocBook might actually be very useful, I thought I'd...
3
by: Justine Hlista | last post by:
I'm using xalan-j_2_6_0 and trying to get an example from Michael Kay's book to work: <xsl:template match="/"> <xsl:variable name="rainbow"> <color>red</color> <color>blue</color>...
4
by: Ringo Langly | last post by:
Hi all, I'm a seasoned web programmer, but I've never touched XSLT. It's always been one of those acronyms I've never needed to educate myself on. Now... we're working with a web content...
3
by: Ian Roddis | last post by:
Hello, I want to embed SQL type queries within an XML data record. The XML looks something like this: <DISPLAYPAGE> <FIELD NAME="SERVER" TYPE="DROPDOWN"> <OPTION>1<OPTION> <OPTION>2<OPTION>...
0
by: DAnne | last post by:
Hi, I'm very new to xslt and this is my first time posting to a Forum so please forgive me if I transgress any protocols. I have to do a tally report. This report is divided up into sections....
18
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to...
14
by: Lee | last post by:
I have a xml file, here is sample part: <?xml version="1.0" encoding="UTF-8"?> <ProducsList> <Product id="1"> <SpecList> <Spec> <SpecLabel>Height</SpecLabel> <SpecValue>10</SpecValue>...
2
by: astroboiii | last post by:
New to the whole xml thing and finding w3schools to be an excellent resource. Now down to my question: I have several xml files I need to parse through and grab relevant information from and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.