473,587 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSL: NOT equal checking for node?

Hi,

I need to know how I can check to see if a particular node is NOT equal
to a SET of values.

i.e. a valid form of : <xsl:template match!="H" && match!="Y"&&
match!="Z">

I have an XML document of the foll format:

<ROOT>
<A>1</A>
<B>2</B>
<C>3</C>
.....
<H>4</H>
....
</ROOT>

I need to transform this into another format. Only the nodes <H>, <X>,
<Z> need special handling, which i refer to, via a corresponding
template calls.

All the other nodes, need to be transformed like this:

<A>1</A> becomes <A><Value>1</Value></A>

My xsl looks something like this:

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

/****template calls for H, X, Z**********/

<xsl:template match="H">
//special handling for <H>
</xsl:template>

How do I say: "for all nodes that are NOT H, X and Z, do this:" ?

something like:

for each child of root
not equal to X, H, Z
do the following:

Thanks for any help
Rohit.

Dec 1 '05 #1
7 10386
This is basics -- you need to read a good book.

Use the XPath not() function and the "=" operator.
Almost never use the "!=" operator, especially if you are not 100% sure you
know what you're doing...
Cheers,
Dimitre Novatchev.
<Pi******@hotma il.com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.com...
Hi,

I need to know how I can check to see if a particular node is NOT equal
to a SET of values.

i.e. a valid form of : <xsl:template match!="H" && match!="Y"&&
match!="Z">

I have an XML document of the foll format:

<ROOT>
<A>1</A>
<B>2</B>
<C>3</C>
....
<H>4</H>
...
</ROOT>

I need to transform this into another format. Only the nodes <H>, <X>,
<Z> need special handling, which i refer to, via a corresponding
template calls.

All the other nodes, need to be transformed like this:

<A>1</A> becomes <A><Value>1</Value></A>

My xsl looks something like this:

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

/****template calls for H, X, Z**********/

<xsl:template match="H">
//special handling for <H>
</xsl:template>

How do I say: "for all nodes that are NOT H, X and Z, do this:" ?

something like:

for each child of root
not equal to X, H, Z
do the following:

Thanks for any help
Rohit.

Dec 1 '05 #2
Hi,

Thanks for your reply.

I just reread my post - i hope I didn't mislead you my saying
"particular node is NOT equal to a SET of values."

Just to clarify, i really want to be looking for all nodes other than
X, Y, and Z, and not their values as I had posted.

been struggling with this for a while, could you post a snippet plz?

Dec 1 '05 #3
Pi******@hotmai l.com wrote:
Just to clarify, i really want to be looking for all nodes other than
X, Y, and Z, and not their values as I had posted.


*[not(self::X)][not(self::Y)][not(self::Z)]
--
Johannes Koch
Spem in alium nunquam habui praeter in te, Deus Israel.
(Thomas Tallis, 40-part motet)
Dec 1 '05 #4
> How do I say: "for all nodes that are NOT H, X and Z, do this:" ?

In XSLT one doesn't need to specifically write this.

you will have two templates:

<xsl:template match="*">
<!-- Whatever general transformation necessary here -->

</xsl:template>

<xsl:template match="H | X | Z">
<!-- A more specialized transformation here -->

</xsl:template>

The second template overrides the first for elements of type H, X, Z.

Just try it :o)
Cheers,
Dimitre Novatchev

<Pi******@hotma il.com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.com...
Hi,

I need to know how I can check to see if a particular node is NOT equal
to a SET of values.

i.e. a valid form of : <xsl:template match!="H" && match!="Y"&&
match!="Z">

I have an XML document of the foll format:

<ROOT>
<A>1</A>
<B>2</B>
<C>3</C>
....
<H>4</H>
...
</ROOT>

I need to transform this into another format. Only the nodes <H>, <X>,
<Z> need special handling, which i refer to, via a corresponding
template calls.

All the other nodes, need to be transformed like this:

<A>1</A> becomes <A><Value>1</Value></A>

My xsl looks something like this:

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

/****template calls for H, X, Z**********/

<xsl:template match="H">
//special handling for <H>
</xsl:template>

How do I say: "for all nodes that are NOT H, X and Z, do this:" ?

something like:

for each child of root
not equal to X, H, Z
do the following:

Thanks for any help
Rohit.

Dec 1 '05 #5
Johannes Koch wrote:
Pi******@hotmai l.com wrote:
Just to clarify, i really want to be looking for all nodes other than
X, Y, and Z, and not their values as I had posted.


*[not(self::X)][not(self::Y)][not(self::Z)]


Probably far easier is to declare the null template for the unwanted
element types:

<xsl:template match="X|Y|Z"/>

///Peter
--
XML FAQ: http://xml.silmaril.ie/

Dec 1 '05 #6
Thanks. much better. The <xsl:template match="*"> seems to fit my
needs.

I have run into another problem,

1) how do I call the * template?

I'm need to convert all tags (other than those with special handling)
of the form
<A>1234<A>

to

<TAG>
<NAME>A</NAME>
<VALUE>1234</VALUE>
</TAG>

<xsl:template match="INPUT">
<NEW>
<A><xsl:value-of select="A"/></A>
<B><xsl:value-of select="B"/></B>
<xsl:apply-templates select="* />
<xsl:apply-templates select="SPECIAL " />
</NEW>
</xsl:template>
-----------------------------------------------------------------------------------
I must have the special handling tag after the * handling.

2) The * template is included below. Is it correct to say node() to get
the node name?
-----------------------------------------------------------------------------------
<xsl:template match="*">
<xsl:variable name="tag_value ">
<xsl:value-of select="."/>
</xsl:variable>
<FEATURE>
<MNEMONIC><xsl: value-of select='node()'/></MNEMONIC>
<VALUE><xsl:val ue-of select="$tag_va lue"/></VALUE>
</FEATURE>
</xsl:template>
---------------------------------------------------------------------------------------------------------

Dec 2 '05 #7
Pi******@hotmai l.com wrote:
Thanks. much better. The <xsl:template match="*"> seems to fit my
needs.

I have run into another problem,

1) how do I call the * template?


You don't. It gets used by anything that is not otherwise matched by an
existing template.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Dec 3 '05 #8

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

Similar topics

15
2556
by: Simon Harvey | last post by:
Hi everyone, I am fairly new to learning about xsl and xml, but one thing I have noticed is that anyone offering a tutorial or lesson on it seems to think that its the most incredible invention ever made. I don't. I'm wondering what everyone else thinks. I know the smart answer is, use it if you need it and don't if you don't.
5
1639
by: Kasp | last post by:
Hi, I have an XSL here...and though I understand XML, I am having a hard time understanding what this XSL does? Any help will be appreciated. TIA <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output indent="yes"/> <xsl:key name="pageKey" match="//HierarchyMember" use="@PageKey"/>
7
2157
by: Sharon | last post by:
Hi, Is it possible to check parameters against other parameters, as in: <xsl:variable name="tableData"> <xsl:apply-templates select="general/data/rows/row/fvalues" mode="tableData" /> </xsl:variable> (The parts I'm referring to are in capitals). Because this gives me no
14
12154
by: inquirydog | last post by:
Hi- One frusterating thing for me with xsl is that I don't know how to make xslt throw some sort of exception when a value-of path does not exist. For instance, suppose I have the following line in xslt <xsl:value-of select="/blah/q" /> and my xml document does not have a node /blah/q. The output would
6
3672
by: Virginia Kirkendall | last post by:
Hi: I'm new with this & need help creating a XSL table that looks like the following: --------------------------------------------------------- | | | | | | |Title |CrossCut |Institution |START |END | | | | | | | | | |PI | | | | | | | | |
6
4742
by: Loopy | last post by:
I'm learning XML and XSL at the moment, but I still can't get my head around the concept of non-updatable variables. I know we can use recursion to cycle through a data structure and get the sum (say) of a list of numbers, or a concatination of a set of strings (again, example), but if I wanted to, for example, keep that value available for...
2
1720
by: Norman Barker | last post by:
Hi, I have the following template <xsl:template match="midas:Request"> <xsl:variable name="var1" select="string(./midas:DataDescriptorGUID/@GUID)"/> <test> <result1><xsl:copy-of select="$OGC_Type"/></result1> <result2><xsl:copy-of select="$OGC_Type"/></result2> </test>
4
1544
by: Tjerk Wolterink | last post by:
I've xml code like this: roles.xml: <?xml version="1.0" encoding="ISO-8859-1"?> <roles xmlns="http://www.wolterinkwebdesign.com/xml/roles"> <!-- ! The admin role. ! And admin should have all permisions to do its task !
6
1898
by: Christoph | last post by:
I'm trying to come up with a stylesheet where, when the rows are displayed, duplicate game names are not shown on subsequent rows. It works but doesn't work properly. If I sort the data using <xsl:sortprior to processing, it's not checking against the previous row after the sort but instead the previous row from the original data set. Here...
0
7915
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8205
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7967
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2347
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.