freelanceprogrammers.org Forum Index » XML / XSL
I Solved the Problems: Try to Learn Hot to Sort XML in a Sep
Joined: 01 May 2005
Posts: 6
I Solved the Problems: Try to Learn Hot to Sort XML in a Sep
It now does everything it is suppose to do, including sorting. I thought it
appropriate to
post the XSLT part to this project since it is the main player in the
process. However,
the coding for the openning XML page is also important so I will also post
it. If anyone
wants to see all the code and a screenshot, go to XMLpitstop dot com. It is
located in
the advanced XML discussions group.
mainPage.xml
<?xml version="1.0" ?>
<?xml-stylesheet href="parseTrans.xsl" type="text/xsl" ?>
<!-- Some of what follows may not be necessary. -->
<!DOCTYPE html [
<!ENTITY data SYSTEM "./data.xml" >
<!ELEMENT data (item+) >
<!ELEMENT item ANY >
<!ATTLIST item ref ID #IMPLIED >
<!ELEMENT title (#PCDATA) >
<!ELEMENT edition (#PCDATA) >
<!ELEMENT copyright (#PCDATA) >
<!ELEMENT author (#PCDATA) >
<!ELEMENT publisher (#PCDATA) >
<!ELEMENT isbn (#PCDATA) >
<!ELEMENT lccn (#PCDATA) >
<!ELEMENT price ANY >
<!ELEMENT subject ANY >
]>
<!-- This is a reference to the entity created above. -->
<data>&data;</data>
=================================
parseTrans.xsl
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="html" indent="yes" />
<xsl:template name="SomeStuff" match="/">
<html>
<link rel="stylesheet" type="text/css" href="my_bookstyle.css" />
<head>
<title>MY LIBRARY</title>
</head>
<body>
<p>A LINK TO GO HERE</p><!-- DISPLAYS THIS -->
<p>ANOTHER LINK TO GO HERE</p> <!-- DISPLAYS THIS -->
<xsl:for-each select="document(`data.xml`) /data/item/.">
<xsl:sort data-type="text" select="title" /><!-- NOTICE THE data-type
ENTRY -->
<table>
<xsl:call-template name="aTable" />
</table>
<xsl:value-of select="*/*" /><!-- NOTICE HOW THIS WAS HANDLED -->
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template name="aTable">
<tr class="highlightBeige"><td> TITLE </td><td><xsl:value-of
select="title" /></td></tr>
<tr><td>EDITION</td><td><xsl:value-of select="edition" /></td></tr>
<!-- for-each loop -->
<xsl:for-each select="author">
<tr><td>AUTHOR/s</td><td><xsl:value-of select="." /></td></tr>
</xsl:for-each>
<tr><td>PUBLISHER</td><td><xsl:value-of select="publisher" /></td></tr>
<tr><td>ISBN</td><td><xsl:value-of select="isbn" /></td></tr>
<tr><td>LCCN</td><td><xsl:value-of select="lccn" /></td></tr>
<tr><td>PRICE</td><td><xsl:value-of select="price" /></td></tr>
<tr><td class="aBorderLtd">SUBJECT</td><td
class="aBorderRtd"><p><xsl:value-of select="subject" /></p></td></tr>
<br />
</xsl:template>
</xsl:stylesheet>
Joined: 02 May 2005
Posts: 1
I Solved the Problems: Try to Learn Hot to Sort XML in a Sep
>>>>> "charlie" == charlie chan <charlie_chan> writes:
charlie> It now does everything it is suppose to do, including
charlie> sorting. I thought it appropriate to post the XSLT part
charlie> to this project since it is the main player in the
charlie> process. However, the coding for the openning XML page
charlie> is also important so I will also post it. If anyone
charlie> wants to see all the code and a screenshot, go to
charlie> XMLpitstop dot com. It is located in the advanced XML
charlie> discussions group.
Yet your solution is a bit flawed. You incorporate the data from the
`external XML file` data.xml in two ways, but use only one. The
content of mainPage.XML doesn`t seem to matter in your solution,
except for referencing the style sheet.
charlie> mainPage.xml
charlie> <?xml version="1.0" ?>
charlie> <?xml-stylesheet href="parseTrans.xsl" type="text/xsl" ?>
charlie> <!-- Some of what follows may not be necessary. -->
charlie> <!DOCTYPE html [
charlie> <!ENTITY data SYSTEM "./data.xml" >
charlie> [..]
charlie> <!ELEMENT subject ANY >
charlie> ]>
charlie> <!-- This is a reference to the entity created above. -->
charlie> <data>&data;</data>
There is no need to actually use the entity, as you do not work on the
data of you basic xml-tree, but only on the one you select using the
document function (see below).
Try removing &data; and see what happens :-) If it still does work,
remove it in the installed version, to avoid confusion later on. If,
for example, someone would like to use another data file and changes
the entity declaration that would have no effect and leave with some
weird error.
charlie> =================================
charlie> parseTrans.xsl
charlie> <?xml version="1.0" ?>
charlie> <xsl:stylesheet version="1.0"
charlie> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
charlie> <xsl:output method="html" indent="yes" />
charlie> <xsl:template name="SomeStuff" match="/">
This is the only time you match anything from mainPage.xml and that is
an unconstrained root element. So anything like <Dummy/> should do
as content of mainPage.xml .
charlie> <html>
charlie> <link rel="stylesheet" type="text/css" href="my_bookstyle.css"
/>
charlie> <head>
charlie> <title>MY LIBRARY</title>
charlie> </head>
charlie> <body>
charlie> <p>A LINK TO GO HERE</p><!-- DISPLAYS THIS -->
charlie> <p>ANOTHER LINK TO GO HERE</p> <!-- DISPLAYS THIS -->
charlie>
charlie> <xsl:for-each select="document(`data.xml`) /data/item/.">
Here you actually import the data using the document function. That
is the data you work upon. If you`d like to use some other data, here
and only here would be the place to change the reference.
charlie> <xsl:sort data-type="text" select="title" /><!-- NOTICE THE
data-type
charlie> ENTRY -->
charlie> [..]
charlie> </xsl:template>
charlie> </xsl:stylesheet>
Best wishes
Oliver
--
------------ DISCLAIMER: I do not speak for anyone but myself. ----------
Oliver Meyer omeyer@...
phone: +49 (2 41) 80 - 2 13 13 Department of Computer Science III
fax: +49 (2 41) 80 - 2 22 18 Aachen University of Technology
Joined: 01 May 2005
Posts: 6
I Solved the Problems: Try to Learn Hot to Sort XML in a Sep
Oliver Meyer wrote:
>
>
>>>>>>"charlie" == charlie chan <charlie_chan> writes:
>>>>>>
>>>>>>
>
> charlie> It now does everything it is suppose to do, including
> charlie> sorting. I thought it appropriate to post the XSLT part
> charlie> to this project since it is the main player in the
> charlie> process. However, the coding for the openning XML page
> charlie> is also important so I will also post it. If anyone
> charlie> wants to see all the code and a screenshot, go to
> charlie> XMLpitstop dot com. It is located in the advanced XML
> charlie> discussions group.
>
>Yet your solution is a bit flawed. You incorporate the data from the
>`external XML file` data.xml in two ways, but use only one. The
>content of mainPage.XML doesn`t seem to matter in your solution,
>except for referencing the style sheet.
>
> charlie> mainPage.xml
> charlie> <?xml version="1.0" ?>
> charlie> <?xml-stylesheet href="parseTrans.xsl" type="text/xsl" ?>
> charlie> <!-- Some of what follows may not be necessary. -->
> charlie> <!DOCTYPE html [
> charlie> <!ENTITY data SYSTEM "./data.xml" >
> charlie> [..]
> charlie> <!ELEMENT subject ANY >
> charlie> ]>
> charlie> <!-- This is a reference to the entity created above. -->
> charlie> <data>&data;</data>
>
>There is no need to actually use the entity, as you do not work on the
>data of you basic xml-tree, but only on the one you select using the
>document function (see below).
>
>Try removing &data; and see what happens :-) If it still does work,
>remove it in the installed version, to avoid confusion later on. If,
>for example, someone would like to use another data file and changes
>the entity declaration that would have no effect and leave with some
>weird error.
>
> charlie> =================================
> charlie> parseTrans.xsl
> charlie> <?xml version="1.0" ?>
> charlie> <xsl:stylesheet version="1.0"
> charlie> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
> charlie> <xsl:output method="html" indent="yes" />
> charlie> <xsl:template name="SomeStuff" match="/">
>
>This is the only time you match anything from mainPage.xml and that is
>an unconstrained root element. So anything like <Dummy/> should do
>as content of mainPage.xml .
>
> charlie> <html>
> charlie> <link rel="stylesheet" type="text/css"
href="my_bookstyle.css" />
> charlie> <head>
> charlie> <title>MY LIBRARY</title>
> charlie> </head>
> charlie> <body>
> charlie> <p>A LINK TO GO HERE</p><!-- DISPLAYS THIS -->
> charlie> <p>ANOTHER LINK TO GO HERE</p> <!-- DISPLAYS THIS -->
> charlie>
> charlie> <xsl:for-each select="document(`data.xml`) /data/item/.">
>
>Here you actually import the data using the document function. That
>is the data you work upon. If you`d like to use some other data, here
>and only here would be the place to change the reference.
>
> charlie> <xsl:sort data-type="text" select="title" /><!-- NOTICE THE
data-type
> charlie> ENTRY -->
>
> charlie> [..]
>
> charlie> </xsl:template>
> charlie> </xsl:stylesheet>
>
>Best wishes
>Oliver
>
>
>
>
>
>
>
Here is what happens if <data>&data</data> is removed.
XML document must have a top level element. Error processing resource
`file:///C:/XML_files/Books/mainPage.xml`.|
|
|I learned how to use the entity that way from a magazine article by Ian
Graham found in CPU
Magazine http://www.utoronto.ca/ian
I have also removed the name="stuff.xml". I must have sent out an older
copy of the XSLT file.
The only problem I am having with this project (at the moment) is I need
to learn how to do
a better job of sorting the author/s since some books have more than one
author. This causes
the sort to do a less than perfect job.
|
Joined: 02 May 2005
Posts: 10
I Solved the Problems: Try to Learn Hot to Sort XML in a Sep
You only remove the entity &data; not the root element
<data/> in Oliver`s suggestion.
--- charlie_chan <charlie_chan@...>
wrote:
> Oliver Meyer wrote:
>
> >
> >
> >>>>>>"charlie" == charlie chan <charlie_chan>
> writes:
> >>>>>>
> >>>>>>
> >
> > charlie> It now does everything it is suppose
> to do, including
> > charlie> sorting. I thought it appropriate to
> post the XSLT part
> > charlie> to this project since it is the main
> player in the
> > charlie> process. However, the coding for the
> openning XML page
> > charlie> is also important so I will also post
> it. If anyone
> > charlie> wants to see all the code and a
> screenshot, go to
> > charlie> XMLpitstop dot com. It is located in
> the advanced XML
> > charlie> discussions group.
> >
> >Yet your solution is a bit flawed. You incorporate
> the data from the
> >`external XML file` data.xml in two ways, but use
> only one. The
> >content of mainPage.XML doesn`t seem to matter in
> your solution,
> >except for referencing the style sheet.
> >
> > charlie> mainPage.xml
> > charlie> <?xml version="1.0" ?>
> > charlie> <?xml-stylesheet href="parseTrans.xsl"
> type="text/xsl" ?>
> > charlie> <!-- Some of what follows may not be
> necessary. -->
> > charlie> <!DOCTYPE html [
> > charlie> <!ENTITY data SYSTEM "./data.xml" >
> > charlie> [..]
> > charlie> <!ELEMENT subject ANY >
> > charlie> ]>
> > charlie> <!-- This is a reference to the entity
> created above. -->
> > charlie> <data>&data;</data>
> >
> >There is no need to actually use the entity, as you
> do not work on the
> >data of you basic xml-tree, but only on the one you
> select using the
> >document function (see below).
> >
> >Try removing &data; and see what happens :-) If it
> still does work,
> >remove it in the installed version, to avoid
> confusion later on. If,
> >for example, someone would like to use another data
> file and changes
> >the entity declaration that would have no effect
> and leave with some
> >weird error.
> >
> > charlie> =================================
> > charlie> parseTrans.xsl
> > charlie> <?xml version="1.0" ?>
> > charlie> <xsl:stylesheet version="1.0"
> > charlie>
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
> > charlie> <xsl:output method="html" indent="yes"
> />
> > charlie> <xsl:template name="SomeStuff"
> match="/">
> >
> >This is the only time you match anything from
> mainPage.xml and that is
> >an unconstrained root element. So anything like
> <Dummy/> should do
> >as content of mainPage.xml .
> >
> > charlie> <html>
> > charlie> <link rel="stylesheet"
> type="text/css" href="my_bookstyle.css" />
> > charlie> <head>
> > charlie> <title>MY LIBRARY</title>
> > charlie> </head>
> > charlie> <body>
> > charlie> <p>A LINK TO GO HERE</p><!-- DISPLAYS
> THIS -->
> > charlie> <p>ANOTHER LINK TO GO HERE</p> <!--
> DISPLAYS THIS -->
> > charlie>
> > charlie> <xsl:for-each
> select="document(`data.xml`) /data/item/.">
> >
> >Here you actually import the data using the
> document function. That
> >is the data you work upon. If you`d like to use
> some other data, here
> >and only here would be the place to change the
> reference.
> >
> > charlie> <xsl:sort data-type="text"
> select="title" /><!-- NOTICE THE data-type
> > charlie> ENTRY -->
> >
> > charlie> [..]
> >
> > charlie> </xsl:template>
> > charlie> </xsl:stylesheet>
> >
> >Best wishes
> >Oliver
> >
> >
> >
> >
> >
> >
> >
> Here is what happens if <data>&data</data> is
> removed.
>
> XML document must have a top level element. Error
> processing resource
> `file:///C:/XML_files/Books/mainPage.xml`.|
> |
>
> |I learned how to use the entity that way from a
> magazine article by Ian
> Graham found in CPU
> Magazine http://www.utoronto.ca/ian
>
> I have also removed the name="stuff.xml". I must
> have sent out an older
> copy of the XSLT file.
> The only problem I am having with this project (at
> the moment) is I need
> to learn how to do
> a better job of sorting the author/s since some
> books have more than one
> author. This causes
> the sort to do a less than perfect job.
> |
>
>
>
>
> Yahoo! Groups Links
>
>
> xml-doc-unsubscribe@yahoogroups.com
>
>
>
>
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Joined: 01 May 2005
Posts: 6
I Solved the Problems: Try to Learn Hot to Sort XML in a Sep
charlie_chan wrote:
>Oliver Meyer wrote:
>
>
>
>>
>>
>>
>>
>>>>>>>"charlie" == charlie chan <charlie_chan> writes:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>> charlie> It now does everything it is suppose to do, including
>> charlie> sorting. I thought it appropriate to post the XSLT part
>> charlie> to this project since it is the main player in the
>> charlie> process. However, the coding for the openning XML page
>> charlie> is also important so I will also post it. If anyone
>> charlie> wants to see all the code and a screenshot, go to
>> charlie> XMLpitstop dot com. It is located in the advanced XML
>> charlie> discussions group.
>>
>>Yet your solution is a bit flawed. You incorporate the data from the
>>`external XML file` data.xml in two ways, but use only one. The
>>content of mainPage.XML doesn`t seem to matter in your solution,
>>except for referencing the style sheet.
>>
>> charlie> mainPage.xml
>> charlie> <?xml version="1.0" ?>
>> charlie> <?xml-stylesheet href="parseTrans.xsl" type="text/xsl" ?>
>> charlie> <!-- Some of what follows may not be necessary. -->
>> charlie> <!DOCTYPE html [
>> charlie> <!ENTITY data SYSTEM "./data.xml" >
>> charlie> [..]
>> charlie> <!ELEMENT subject ANY >
>> charlie> ]>
>> charlie> <!-- This is a reference to the entity created above. -->
>> charlie> <data>&data;</data>
>>
>>There is no need to actually use the entity, as you do not work on the
>>data of you basic xml-tree, but only on the one you select using the
>>document function (see below).
>>
>>Try removing &data; and see what happens :-) If it still does work,
>>remove it in the installed version, to avoid confusion later on. If,
>>for example, someone would like to use another data file and changes
>>the entity declaration that would have no effect and leave with some
>>weird error.
>>
>> charlie> =================================
>> charlie> parseTrans.xsl
>> charlie> <?xml version="1.0" ?>
>> charlie> <xsl:stylesheet version="1.0"
>> charlie> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
>> charlie> <xsl:output method="html" indent="yes" />
>> charlie> <xsl:template name="SomeStuff" match="/">
>>
>>This is the only time you match anything from mainPage.xml and that is
>>an unconstrained root element. So anything like <Dummy/> should do
>>as content of mainPage.xml .
>>
>> charlie> <html>
>> charlie> <link rel="stylesheet" type="text/css"
href="my_bookstyle.css" />
>> charlie> <head>
>> charlie> <title>MY LIBRARY</title>
>> charlie> </head>
>> charlie> <body>
>> charlie> <p>A LINK TO GO HERE</p><!-- DISPLAYS THIS -->
>> charlie> <p>ANOTHER LINK TO GO HERE</p> <!-- DISPLAYS THIS -->
>> charlie>
>> charlie> <xsl:for-each select="document(`data.xml`) /data/item/.">
>>
>>Here you actually import the data using the document function. That
>>is the data you work upon. If you`d like to use some other data, here
>>and only here would be the place to change the reference.
>>
>> charlie> <xsl:sort data-type="text" select="title" /><!-- NOTICE THE
data-type
>> charlie> ENTRY -->
>>
>> charlie> [..]
>>
>> charlie> </xsl:template>
>> charlie> </xsl:stylesheet>
>>
>>Best wishes
>>Oliver
>>
>>
>>
>>
>>
>>
>>
>>
>>
>Here is what happens if <data>&data</data> is removed.
>
>XML document must have a top level element. Error processing resource
>`file:///C:/XML_files/Books/mainPage.xml`.|
>|
>
>|I learned how to use the entity that way from a magazine article by Ian
>Graham found in CPU
>Magazine http://www.utoronto.ca/ian
>
>I have also removed the name="stuff.xml". I must have sent out an older
>copy of the XSLT file.
>The only problem I am having with this project (at the moment) is I need
>to learn how to do
>a better job of sorting the author/s since some books have more than one
>author. This causes
>the sort to do a less than perfect job.
>|
>
>
>
>
>Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
>
I understand now and I have removed only the the "&data;" data entity.
It works properly.
Thank you for the info.
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
English Courses in England - reservation calendar script
Land Surveying -Stonex instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
English Courses in England - reservation calendar script
Land Surveying -Stonex instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







