473,802 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validate a sequence on elements with Xslt

Hi

How can I easily ensure that Xml document has elements in certain
order? I think it can be done with Xml schema, but I'd like to use
Xslt, because the validation is a part of Xslt transformations .

Xml document:
<Root>
<Foo/>
<Bar/>
<Bar/>
<Baz/>
<Foo/> <!-- this is in the wrong position -->
</Root>

All elements don't necessary have to exist, but if they do they must
be in the right position. I'd like to have similar a function like this
awk script:

$ echo "FooBarBarBazFo o" | awk '$0 !~ /^(Foo)*(Bar)*(B az)*$/ { print "Error"}'
This is my attempt, quite ugly code. Is there a better way to do this ?
-----
<xsl:template match="/Root">
<xsl:apply-templates select="*"/>
</xsl:template>

<xsl:template match="Foo[not(preceding-sibling::*[name() != 'Foo'])]"/>

<xsl:template match="Bar[not(preceding-sibling::*[name()!='Foo' and
name()!='Bar'])]"/>

<xsl:template match="Baz[not(preceding-sibling::*[name()!='Foo' and
name()!='Bar' and
name()!='Baz'])]"/>
<xsl:template match="*">
<xsl:message terminate="yes" >
<xsl:text>Err or in: </xsl:text>
<xsl:value-of select="name()"/>
</xsl:message>
</xsl:template>
-----

Thanks
--
// ju**********@ik i.fi
\X/
Dec 1 '05 #1
1 1222
I would be using XML Schema and you can make it work with your XSLT
using either XSLT output validation and/or a Schema Aware XSLT
processor like Saxon. Not sure if it makes sense to write your own
validation scripts. Hope that helps.

Sincerely,
The Stylus Studio Team
http://www.stylusstudio.com

Dec 2 '05 #2

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

Similar topics

2
2216
by: sachinik19 | last post by:
Hi, xml file : ------------- <?xml version='1.0'?> <query xmlns='jabber:iq:privacy' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="jabber:iq:privacy privacy.xsd"> <list name="hello"> <item action='allow' order="1"/>
4
1488
by: Lord0 | last post by:
Hi there, Would like to conditionally validate XML i.e. If element <ElementAhas a particular value then element <ElementBmust have a particular value I'm pretty sure I can't do this this with a Schema..... I know I could use an XSLT to check the values of <ElementAand
1
1460
by: luthriaajay | last post by:
I am stuck with a tricky situation. 1)I am reading element values from an XML document mentioned below: InputDocument.xml ----------------- <?xml version="1.0" encoding="UTF-8"?> <FIXML xmlns="http://www.fixprotocol.org/FIXML-4-4">
7
3075
by: C.W.Holeman II | last post by:
For info on the context of my question see the end of this posting. From http://www.w3.org/TR/XHTMLplusMathMLplusSVG/: How can I validate the result of client-side XSLT transform which has the following? <xsl:output method="xml"
0
9699
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9115
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.