473,597 Members | 2,198 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT parsing

Hi,

I have an XML file created by a third party in which an element with a
simple content model has a text value consisting of 2 parts separated by a
colon, like this

<link>machine:p ort</link>

Is XSLT capable of parsing the value of a <link> element, to separately
extract the portions before and after the colon?

Regards
David Walker
Jul 20 '05 #1
6 2853
*David Walker* wrote:
I have an XML file created by a third party in which an element with a
simple content model has a text value consisting of 2 parts separated
by a colon, like this

<link>machine:p ort</link>

Is XSLT capable of parsing the value of a <link> element, to
separately extract the portions before and after the colon?


Yes, e.g.:

<xsl:template match="link">
<xsl:choose>
<xsl:when test="contains( ., ':')">
<xsl:text>Befor e = &quot;</xsl:text>
<xsl:value-of select="substri ng-before(., ':')"/>
<xsl:text>&quot ;, after = &quot;</xsl:text>
<xsl:value-of select="substri ng-after(., ':')"/>
<xsl:text>&quot ;</xsl:text>
</xsl:when>
<xsl:otherwis e>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

--
Andrew Urquhart
- CIWAS CSS FAQ: www.css.nu/faq/ciwas-aFAQ.html
- CIWAS Archive: www.tinyurl.com/ysjbm (Google Groups)
- My reply address is invalid, use: www.andrewu.co.uk/contact/
Jul 20 '05 #2
"David Walker" <da***@cs.cf.ac .uk> wrote:
Hi,

I have an XML file created by a third party in which an element with a
simple content model has a text value consisting of 2 parts separated by a
colon, like this

<link>machine: port</link>

Is XSLT capable of parsing the value of a <link> element, to separately
extract the portions before and after the colon?


I suppose a question about XSLT is a bit more relevant to a group on
style sheets than to a group like, say, rec.knitting... but really,
what is this doing here?

--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 20 '05 #3
*Harlan Messinger* wrote:
*David Walker* wrote:
<link>machine:p ort</link>
Is XSLT capable of parsing the value of a <link> element, to
separately extract the portions before and after the colon?


I suppose a question about XSLT is a bit more relevant to a group on
style sheets than to a group like, say, rec.knitting... but really,
what is this doing here?


comp.infosystem s.www.authoring. /stylesheets/

XSLT; extensible /stylesheet/ language transformations

CSS and XSLT are both stylesheets.
To quote the FAQ:

'At the moment, almost all discussion on this group relates to CSS,
although that might not always be so. This document does not aim
to be a complete tutorial in stylesheets or in CSS.'

Pragmatically speaking comp.text.xml is more applicable at the present
time, but that is not obvious given this newsgroups dual purpose name.
Personally I'd prefer to see a comp.text.xml.x slt group, XSLT being a
subset of XML.
--
Andrew Urquhart
- CIWAS CSS FAQ: www.css.nu/faq/ciwas-aFAQ.html
- Archive: www.tinyurl.com/ysjbm (Google Groups)
- My reply address is invalid, use: www.andrewu.co.uk/contact/
Jul 20 '05 #4

"Andrew Urquhart" <us************ **************@ spam.invalid> wrote in
message news:XhDAc.150$ in5.136@newsfe1-win...
*Harlan Messinger* wrote:
*David Walker* wrote:
<link>machine:p ort</link>
Is XSLT capable of parsing the value of a <link> element, to
separately extract the portions before and after the colon?


I suppose a question about XSLT is a bit more relevant to a group on
style sheets than to a group like, say, rec.knitting... but really,
what is this doing here?


comp.infosystem s.www.authoring. /stylesheets/

XSLT; extensible /stylesheet/ language transformations

CSS and XSLT are both stylesheets.
To quote the FAQ:

'At the moment, almost all discussion on this group relates to CSS,
although that might not always be so. This document does not aim
to be a complete tutorial in stylesheets or in CSS.'

Pragmatically speaking comp.text.xml is more applicable at the present
time, but that is not obvious given this newsgroups dual purpose name.
Personally I'd prefer to see a comp.text.xml.x slt group, XSLT being a
subset of XML.


Ah. Understood. I apologize.

Jul 20 '05 #5
"David Walker" <da***@cs.cf.ac .uk> wrote in message news:<ca******* ***@news.swman. net.uk>...
Hi,

I have an XML file created by a third party in which an element with a
simple content model has a text value consisting of 2 parts separated by a
colon, like this

<link>machine:p ort</link>

Is XSLT capable of parsing the value of a <link> element, to separately
extract the portions before and after the colon?

Regards
David Walker


David,

I suppose there are many ways of achieving that. Here is just one example:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select="link"/>
</xsl:template>
<xsl:template match="link">
<xsl:variable name="machine" select="substri ng-before( . , ':' ) "/>
<xsl:variable name="port" select="substri ng-after( . , ':' ) "/>
<xsl:element name="link">
<xsl:element name="machine">
<xsl:value-of select="$machin e"/>
</xsl:element>
<xsl:element name="port">
<xsl:value-of select="$port"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

This will transform Your example

<?xml version="1.0" encoding="UTF-8"?>
<link>machine:p ort</link>

To the following:

<?xml version="1.0" encoding="UTF-8"?>
<link>
<machine>machin e</machine>
<port>port</port>
</link>

Is this something like You were after?

Rgds,

<kimmo/>
Jul 20 '05 #6
On Fri, 18 Jun 2004 08:47:42 -0400, Harlan Messinger
<hm************ *******@comcast .net> wrote:
"David Walker" <da***@cs.cf.ac .uk> wrote: [...]
Is XSLT capable of parsing the value...

I suppose a question about XSLT is a bit more relevant to a group on
style sheets than to a group like, say, rec.knitting... but really,
what is this doing here?


This NG is not restricted to only discuss CSS, in fact any stylesheet
technology that is applicable to the www may be discussed here.

http://css.nu/faq/ciwas-mFAQ.html#C02

--
Rex

Jul 20 '05 #7

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

Similar topics

9
4157
by: Hayko Riemenschneider | last post by:
Hi! I've got me an XSL tranformation stylesheet for my XML file. In the XSL file I now wish to use PHP to do some scripting. So I thought I'll use the PIs like this: <xsl:processing-instruction name="php"> echo $hello; </xsl:processing-instruction>
5
19351
by: K. N. | last post by:
Is there any good and fast Python module for XSLT processing ? I'm going to use XML and XSLT to generate web pages, so I need XSLT processor that will be able to transform for example a DOM object in memory - I don't want to create XML file containing data and then load it and transform with XSLT, but I want to do this at once - without writing to a temporary file. Actually I've seen alot articles about parsing XML, but nothing about...
3
4132
by: David Walker | last post by:
Hi, I have an XML file created by a third party in which an element with a simple content model has a text value consisting of 2 parts separated by a colon, like this <link>machine:port</link> Is XSLT capable of parsing the value of a <link> element, to separately extract the portions before and after the colon?
12
3213
by: gipsy boy | last post by:
Hello, I have sort of a big problem. I would really appreciate any help you could give me. I made a web service in C++ that throws XML to the client (browser). But, the XSLT transormation (xml->html) doen't happen! I have XSLT files for this, they work, I mean when I put the output of the app as an XML file on some server, and make it use the XSLT files to transform into HTML, it works, I get a HTML page.
3
2006
by: crc128 | last post by:
Hi, I'm looking at using XML and XSLT with apache cocoon to automatically generate html files for a site. the problem I'm having is that I want one of the pages to display a google map, but the google API requires the following line in the output HTML: <script src="http://maps.google.com/maps?file=api&v=2&key=abcdefg" type="text/javascript"> The problem is that I can't get the '&' to properly make it into the result. I can get &amp;. ...
2
2133
by: veracon | last post by:
Hello, I'm looking to use XML and XSLT for templates in a system I'm writing, however I'm not really sure which parser is the "best". Basically, which library has the most features, and which is the most supported? A guide I saw mentioned importing xml.xslt, however it appears the xml module/package contains pretty much nothing - xml.xslt outputs an exception, No module named xslt.
9
1775
by: daph4ntom | last post by:
Right, I need some some views on the pros and cons of using XSLT versus ASP.NET 2.0 for the Presentation layer of an app. My company are looking at creating multiple sites and multi lingual support going forward... I have looked at Chris Lovetts post http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnexxml/html/xml02192001.asp Some of his views are still relevant.
12
11575
by: Chris | last post by:
Hi, Just wondering if anyone out there knows if it is possible to convert a CSV to xml using XSLT? I've seen a lot of examples of xml to CSV, but is it possible to go back the other way? I don't want to have to use some external program or script to parse the csv first if possible
2
2496
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 produce a new xml file. This needs to be automated through ant. The ant script is working fine, and I am usign the <transform> function to use my xslt file and go through all the required xml files, parse them, style them, and ultimately generate my...
0
7962
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
8267
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8258
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6681
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
5844
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
3921
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2394
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
1
1493
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1229
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.