473,789 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

New xml dude needs help with xslt

I have

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="categor y/entry">
<xsl:value-of select="job"/><br/>
<xsl:value-of select="date"/><br/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

and my .xml file has

<category>Job s</category>
<entry>
<job>Plumber</job>
<date>12/5/04</date>
</entry>
<category>Teams </category>
<entry>
<job>Jets</job>
<date>12/3/04</date>
</entry>

I want to have unlimited entries, but I also want to run a for-each on
the categories. How would I structure something like that? I'm
absolutely new to this, so please bear with me! Thanks.

Sep 15 '05 #1
6 1348
Le 14 Sep 2005 17:52:42 -0700
"Guttyguppy " <gu********@gma il.com> a écrit:
I have

[xsl snip]
and my .xml file has
[snip]

I want to have unlimited entries, but I also want to run a for-each on
the categories. How would I structure something like that? I'm
absolutely new to this, so please bear with me! Thanks.


I suggest the following data structure

<?xml version="1.0"?>
<categories>
<category>
<name>Jobs</name>
<entries>
<entry>
<job>Plumber</job>
<date>15/504</date>
</entry>
<entry>
[...]
</entry>
</entries>
</category>
<category>
<name>Teams</name>
<entries>
<entry>
<name>...</name>
<date>...</date>
</entry>
</entries>

</category>
</categories>

with the sheet (using apply-templates instead of for-each)

<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="no "/>
<xsl:strip-space elements="*"></xsl:strip-space>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates></xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="category/name"></xsl:template>
<xsl:template match="job|date ">
<xsl:apply-templates></xsl:apply-templates><br/>
</xsl:template>
</xsl:stylesheet>

--
nicolas //
Sep 15 '05 #2
Guttyguppy wrote:
I have

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="categor y/entry">
<xsl:value-of select="job"/><br/>
<xsl:value-of select="date"/><br/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

and my .xml file has

<category>Job s</category>
<entry>
<job>Plumber</job>
<date>12/5/04</date>
</entry>
<category>Teams </category>
<entry>
<job>Jets</job>
<date>12/3/04</date>
</entry>

I want to have unlimited entries, but I also want to run a for-each on
the categories. How would I structure something like that? I'm
absolutely new to this, so please bear with me! Thanks.


Nicolas has already suggested a different markup design, which is more
explicit and properly nested. The trick is to enclose things in the
elements which name what they are -- personally I prefer compactness,
especially where the data is categorical:

<data>
<entry cat="Jobs" job="Plumber" date="2004-05-12"/>
<entry cat="Teams" job="Jets" date="2004-03-12
</data>

I STRONGLY recommend using ISO 8601 dates in the format given: they are
much easier to manipulate.

Then you don't need for-each at all:

<xsl:apply-templates select="/data/entry">
<xsl:sort select="@cat"/>
<xsl:sort select="@date"/>
</xsl:apply-templates>

///Peter
Sep 16 '05 #3
Thanks Nicolas,
I'm a bit confused by the line,
<xsl:template match="job|date ">
because I may have other things besides those two. How can I allow for
an unlimited number of data-types under "entry"?
nicolas wrote:
Le 14 Sep 2005 17:52:42 -0700
"Guttyguppy " <gu********@gma il.com> a écrit:
I have

[xsl snip]
and my .xml file has
[snip]

I want to have unlimited entries, but I also want to run a for-each on
the categories. How would I structure something like that? I'm
absolutely new to this, so please bear with me! Thanks.


I suggest the following data structure

<?xml version="1.0"?>
<categories>
<category>
<name>Jobs</name>
<entries>
<entry>
<job>Plumber</job>
<date>15/504</date>
</entry>
<entry>
[...]
</entry>
</entries>
</category>
<category>
<name>Teams</name>
<entries>
<entry>
<name>...</name>
<date>...</date>
</entry>
</entries>

</category>
</categories>

with the sheet (using apply-templates instead of for-each)

<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="no "/>
<xsl:strip-space elements="*"></xsl:strip-space>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates></xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="category/name"></xsl:template>
<xsl:template match="job|date ">
<xsl:apply-templates></xsl:apply-templates><br/>
</xsl:template>
</xsl:stylesheet>



--
nicolas //


Sep 19 '05 #4
Tempore 21:50:43, die Monday 19 September 2005 AD, hinc in foro {comp.text.xml} scripsit Guttyguppy <gu********@gma il.com>:
I'm a bit confused by the line,
<xsl:template match="job|date ">
because I may have other things besides those two. How can I allow for
an unlimited number of data-types under "entry"?


Use <xsl:template match="entry/*">

If there should be a child element 'foo' of 'entry' that should not be matched, you can exclude it thus:
<xsl:template match="entry/*[not(self::foo)]">

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Gaudiam omnibus traderat W3C, nec vana fides
Sep 19 '05 #5
Thanks everyone, I'll try it and report back!

Joris Gillis wrote:
Tempore 21:50:43, die Monday 19 September 2005 AD, hinc in foro {comp.text.xml} scripsit Guttyguppy <gu********@gma il.com>:
I'm a bit confused by the line,
<xsl:template match="job|date ">
because I may have other things besides those two. How can I allow for
an unlimited number of data-types under "entry"?


Use <xsl:template match="entry/*">

If there should be a child element 'foo' of 'entry' that should not be matched, you can exclude it thus:
<xsl:template match="entry/*[not(self::foo)]">

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Gaudiam omnibus traderat W3C, nec vana fides


Sep 20 '05 #6
Worked like a charm. Thanks again.

Sep 22 '05 #7

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

Similar topics

5
19368
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...
2
2794
by: Tom Corcoran | last post by:
I am working to ease updating of a html page by transforming 2 xml files. I was going to use xslt for this and had bought 2 unopened books, wrox xslt and o'reilly's xslt cookbook. But am now wondering if I am better of learning XQuery instead? Any thought and opinions would be appreciated. Cheers - Tom. The Architect: "Hope, it is the quintessential human delusion,
1
3604
by: Mohit | last post by:
Hi Friends I have to call 1 of the 2 child XSLT files from the Main XSLT file based on some criteria. I want one child XSLT file will be executed by version 1 of XSLT processor and the other by version 2 of XSLT processor based on some condition. Q) How and where shall I write logic or import desirable XSLT on the Fly ? Q) When we call AAA.XSLT then it will be processed by XSLT Processor 1
4
2028
by: Cathie | last post by:
Hi All, I am trying to get my style sheet to work. It works fine in IE but I can't get it to work in .net. Below is the function I use for transforming, where advancedOptionsFile is the path to the file containing an XML document required by the transformation, and xmlSimplified is the XML document to trasform. ---------------------------------------------------------------------------- -------------------------------
4
4825
by: schneider | last post by:
Anyone know if there is a way to dynamicly create a Xslt template/s and use them as an xml transform with-out use files for the Xslt? All the methods I see use files. I want to create a Xslt transform via code? Any examples would be great.
27
4718
by: Chris, Master of All Things Insignificant | last post by:
I have come to greatly respect both Herfried & Cor's reponses and since the two conflicted, I wanted to get some clarification. My orginal post: Herfried, maybe your example here can get you to answer a question I've wondered about for a while. With Me.Label1 .Text = ... .Refresh()
7
2259
by: GS | last post by:
Hi! I am getting an "Invalid Xml" exception when I try to load an xsl file using XslTransform.Load(string url). The Xsl file is valid and works fine if I just rename the file. There are some postings with this problem, but none of them have a solution as yet. If anyone has any ideas on how to resolve this, please do post.
3
2011
by: thomas.porschberg | last post by:
Hi, I want to read records from a database and export it in an arbitrary format. My idea was to feed a class with a String array fetched from the database and let this class fire SAX events as processor input. The basic class hierarchy is:
2
22780
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values in the attribute of an element. Instead of using the <xsl:attribute> element, you can simply place the xpath in the attribute itself. The most common usage of this is in creating hyperlinks.
0
9666
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
10199
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9020
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
7529
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
6769
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
5417
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...
1
4092
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
2
3700
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
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.