473,406 Members | 2,439 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,406 software developers and data experts.

Transform only some elements of xml to html using xslt

Hello All,

I am stuck with a problem. I have an xml file as follows

<parent>
<publisher>
<name>somename</name>
<book1>data1</book1>
<book2>data2</book2>
<book3>data3</book3>
<book4>data4</book4>
</publisher>
</parent>


I want to tranform this xml file into html file. I have written an xsl file for the transformation which is as follows

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:param name="somename">
</xsl:param>
<xsl:template match="/">
<html>
<head><title>Publisher Details</title></head>
<body>
<table border="1">
<xsl:for-each select="parent/publisher[name=$somename]/*">
<xsl:if test="local-name()!='book1' or local-name()!='book3'">
<tr>
<td><b><xsl:value-of select="local-name()" /></b></td>
<xsl:if test="not(current()/*)">
<td><xsl:value-of select="current()" /></td>
</xsl:if>
<xsl:for-each select="current()/*">
<tr>
<td><b><i><xsl:value-of select="local-name()" /></i></b></td>
<td><xsl:value-of select="current()" /></td>
</tr>
</xsl:for-each>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

I want to tranform only some of the elements of xml file into html and not all, therefore I have specified the condition
<xsl:if test="local-name()!='book1' or local-name()!='book3'">
where I do not want book1 and book3 to be included in transformed file.
But the problem is this approach does not work.
Interestingly when I specify only 1 condition, it works, but not when I have more than 1 condition.

Kindly suggest me what I am doing wrong here...or suggest me a good approach to solve such a probelm.
Sep 19 '07 #1
3 1984
jkmyoung
2,057 Expert 2GB
Change the 'or' to an 'and'

<xsl:if test="local-name()!='book1' or local-name()!='book3'">

The problem with this is if the name is 'book1' then local-name()!='book3' is true. If the name is 'book3' then local-name()!='book1 is true.

You want either:
<xsl:if test="not(local-name()=='book1' or local-name()=='book3)'">
OR
<xsl:if test="local-name()!='book1' and local-name()!='book3'">


Also if you want, you could put the condition right into your for-each instead:
<xsl:for-each select="parent/publisher[name=$somename]/*[local-name()!= 'book1'][local-name()!= 'book3']">
Sep 19 '07 #2
jkmyoung
2,057 Expert 2GB
abcdefghijklmnopqrst
Sep 19 '07 #3
Change the 'or' to an 'and'

<xsl:if test="local-name()!='book1' or local-name()!='book3'">

The problem with this is if the name is 'book1' then local-name()!='book3' is true. If the name is 'book3' then local-name()!='book1 is true.

You want either:
<xsl:if test="not(local-name()=='book1' or local-name()=='book3)'">
OR
<xsl:if test="local-name()!='book1' and local-name()!='book3'">


Also if you want, you could put the condition right into your for-each instead:
<xsl:for-each select="parent/publisher[name=$somename]/*[local-name()!= 'book1'][local-name()!= 'book3']">

Thanks a lot for quick reply.
I fixed the problem :)
Sep 19 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Barry Anderberg | last post by:
I have an XML document that I am trying to display in my ASP.NET page. I am using an XSL Transform to display repeating XML data in a specific format. It reads the data, and displays it on my...
5
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an...
8
by: Luther Miller | last post by:
I am using the XML tranform functionality in .NET to transform data in a DataSet into XMLSS using an XSLT file I have created. There are about 100 columns and only about 120 rows in the data...
3
by: Paul Hatcher | last post by:
Hi Is it possible to control the node style that XslTransform uses to output XML? I'm trying to convert a file from XML to RDF and if I do the transform in XmlSpy I get the following ...
3
by: Martin Olson | last post by:
I'm trying to output valid xhtml 1.0 transitional with xslt -- my question is when dealing with elements that have self-closing tags such as <img /> and <input />... I'm getting closing tags on...
0
by: Terry Brown | last post by:
I have an xml file: <?xml version="1.0" encoding="utf-8" ?> <G2Registers xmlns="http://tempuri.org/registers.xsd"> <register> <name>Version Register</name> <address>"00000000"</address>...
1
by: andy | last post by:
Hi I am writing a procedure to load an excel file into an xml file that can be validated before loading it into a database via an api. At the moment I can read the excel file into a dataset...
1
by: Gi | last post by:
Hi, Can anyone tell me you can I transform this kind of XML: <Cont ID='faqs'> <Conts ID=''> <Elements> <Data></Data> <Pergunta></Pergunta> <Resposta></Resposta> </Elements>
3
by: R. P. | last post by:
Subject: XSLT to transform a flat XML file into a structured text file I have an XML file that lists the PDF file segment names and titles of a larger document and looks something like this: ...
12
by: das | last post by:
Hello all, I am using .NET XSLT to transform an XML into another XML file. All this is fine with small files, but when tested with big files (30MB) it is taking between 1hr-2hrs to just transform...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.