Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old June 18th, 2007, 10:55 AM
Chrism2671
Guest
 
Posts: n/a
Default simple XSLT question

I'm new to XSLT/XML and I have a very simple, quick question. i've
been trying to convert simple xml files into CSV files and have made a
simple XSLT template using the w3 tutorials, but it doesn't seem to
display anything. It does display plain text I enter into the
templates, the value-of tags just render whitespace.

If anybody can write a template of just a few lines just to
demonstrate how to get it to display something from this XML I would
be very very very appreciative.

<OrganisationList xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="nhs.uk">
<Organisation OrganisationType="15" ParentOrganisation="5HX"
OrganisationCode="E85053">
<PremisesList>
<Premises SiteOrder="0" mainsite="true" PremisesCode="UB5
4AT^1">
<ContactDetails>
<TextPhone>none</TextPhone>
<Fax>020 8422 8040</Fax>
<Telephone>020 8864 8133</Telephone>
</ContactDetails>
<Address>
<Line1>45 Doncaster Drive</Line1>
<Line2>Northolt</Line2>
<Line3>Middx</Line3>
<Line4>none</Line4>
<Line5>none</Line5>
<PostCode>UB5 4AT</PostCode>
</Address>
<PremisesNameList>
<PremisesName NameType="">
<TheName>Dr Balachandran, G</TheName>
</PremisesName>
</PremisesNameList>
</Premises>
</PremisesList>
<NameList OrganisationCode="E85053">
<Name>
<TheName>Dr Balachandran, G</TheName>
</Name>
</NameList>
</Organisation>
</OrganisationList>

  #2  
Old June 18th, 2007, 01:05 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: simple XSLT question

Chrism2671 wrote:
Quote:
I'm new to XSLT/XML and I have a very simple, quick question. i've
been trying to convert simple xml files into CSV files and have made a
simple XSLT template using the w3 tutorials, but it doesn't seem to
display anything. It does display plain text I enter into the
templates, the value-of tags just render whitespace.
>
If anybody can write a template of just a few lines just to
demonstrate how to get it to display something from this XML I would
be very very very appreciative.
>
<OrganisationList xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="nhs.uk">
^^^^^^^^^^^^^^
With that default namespace declaration your stylesheet needs to declare
that namespace too but bind a prefix to it so that your patterns and
XPath expressions match/select elements in that namespace:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:nhs="nhs.uk">

<xsl:output method="text"/>

<xsl:template match="/">
<xsl:value-of
select="nhs:OrganisationList/nhs:Organisation/nhs:PremisesList/nhs:Premises/nhs:ContactDetails/nhs:Fax"/>
</xsl:template>

</xsl:stylesheet>



--

Martin Honnen
http://JavaScript.FAQTs.com/
  #3  
Old June 18th, 2007, 01:35 PM
Chrism2671
Guest
 
Posts: n/a
Default Re: simple XSLT question

Thanks Martin that's brilliant; I would have never figured that
myself. I've gotten as far as the code below, but it doesn't seem to
like my for-each params, which I have based upon your example. It
doesn't output anything, but doesn't through an error either. Any
ideas what I've done wrong?

Thanks once again,
Chris.

<?xml version='1.0'?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:nhs="nhs.uk">

<xsl:template match="/">
<xsl:for-each select="nhs:OrganisationList/nhs:Organisation">
<xsl:value-of select="nhs:OrganisationList/nhs:Organisation/
nhs:PremisesList/nhs:Premises/nhs:ContactDetails/nhs:Fax"/>
</xsl:for-each>
</xsl:template>

<xsl:template match="OrganisationList">

</xsl:template>
</xsl:stylesheet>

On Jun 18, 1:00 pm, Martin Honnen <mahotr...@yahoo.dewrote:
Quote:
Chrism2671 wrote:
Quote:
I'm new to XSLT/XML and I have a very simple, quick question. i've
been trying to convert simple xml files into CSV files and have made a
simple XSLT template using the w3 tutorials, but it doesn't seem to
display anything. It does display plain text I enter into the
templates, the value-of tags just render whitespace.
>
Quote:
If anybody can write a template of just a few lines just to
demonstrate how to get it to display something from this XML I would
be very very very appreciative.
>
Quote:
<OrganisationList xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="nhs.uk">
>
^^^^^^^^^^^^^^
With that default namespace declaration your stylesheet needs to declare
that namespace too but bind a prefix to it so that your patterns and
XPath expressions match/select elements in that namespace:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:nhs="nhs.uk">
>
<xsl:output method="text"/>
>
<xsl:template match="/">
<xsl:value-of
select="nhs:OrganisationList/nhs:Organisation/nhs:PremisesList/nhs:Premises/nhs:ContactDetails/nhs:Fax"/>
</xsl:template>
>
</xsl:stylesheet>
>
--
>
Martin Honnen
http://JavaScript.FAQTs.com/

  #4  
Old June 18th, 2007, 02:05 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: simple XSLT question

Chrism2671 wrote:
Quote:
<xsl:template match="/">
<xsl:for-each select="nhs:OrganisationList/nhs:Organisation">
<xsl:value-of select="nhs:OrganisationList/nhs:Organisation/
nhs:PremisesList/nhs:Premises/nhs:ContactDetails/nhs:Fax"/>
Inside of the xsl:for-each you need to use XPath expressions relative to
the node the for-each selects. So once you have the for-each select an
nhs:Organisation element you need e.g.
<xsl:value-of
select="nhs:PremisesList/nhs:Premises/nhs:ContactDetails/nhs:Fax"/>





--

Martin Honnen
http://JavaScript.FAQTs.com/
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles