Re: [xsl] XML transformation to RDF with XSLT help

Subject: Re: [xsl] XML transformation to RDF with XSLT help
From: "Eric Bréchemier" <eric.brechemier@xxxxxxxxx>
Date: Thu, 4 May 2006 15:01:10 +0200
On 5/4/06, oknam park <ponda7777@xxxxxxxxxxx> wrote:
And I need to transform this to RDF.

Your expected output is missing... but I can provide some hints based on your xsl:template:

<xsl:template match="gemq:catalogingOrganization">

1) For the sake of clarity, you should replace this choose inside a single template by different templates with different XPath matches, as described previously.

<xsl:choose>                                                    <xsl:when

2) It is very important to note that the XPath expression in the match (here "gemq:catalogingOrganization") defines the context for expressions inside the xsl:template. So when you write "gemq:catalogingOrganization/foaf:name", you are testing whether current gemq:catalogingOrganization has (again) some gemq:catalogingOrganization child with foaf:name grandchild.

You should either write simply "foaf:name" (or the longer
"self::gemq:catalogingOrganization/foaf:name" which is what you

               <xsl:when test="gemq:catalogingOrganization/foaf:phone">

3) you cannot output an rdf:resource element this way. xsl:value-of returns the text value of the XPath expression in the "select".

To output an rdf:resource element, simply write

Optionally, you can add attributes simply using "attribute value
templates" (an expression relative to the source document inside curly

<rdf:resource id="{foaf:name}">

Finally, use xsl:value-of only to output the text of the result element:
select="normalize-space(gemq:catalogingOrganization/foaf:phone)" />

        <xsl:when test="gemq:catalogingOrganization/foaf:homepage">
        <xsl:value-of rdf:resource="{normalize-space(gemq:catalogingOrganization/foaf:homepage)}"/></xsl:when>

Last but not least, you can check following resources on the web:

[1] XSLT Tutorial

[2] XSL Transformations - from Wikipedia, the free encyclopedia

[3] XSL Frequently Asked Questions - maintained by Dave Pawson

[4] Jeni's XSLT Pages - Jeni Tennison

[5] Beginning XSLT by Jeni Tennison

[6] XSLT 2.0 Programmer's Reference, 3rd Edition by Michael Kay

and reference material:
[7] W3C Recommandation - XML Path Language (XPath) Version 1.0

[8] W3C Recommandation - XSL Transformations (XSLT) Version 1.0

Best regards,

Eric BrC)chemier

Current Thread