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 |
(...) 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 test="gemq:catalogingOrganization/foaf:name">
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 meant).
<xsl:value-of select="normalize-space(gemq:catalogingOrganization/foaf:name)"/></xsl:when> <xsl:when test="gemq:catalogingOrganization/foaf:phone"> <xsl:value-of rdf:resource="{normalize-space(gemq:catalogingOrganization/foaf:phone)}"/></xsl:when>
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 <rdf:resource> (...) </rdf:resource>
Optionally, you can add attributes simply using "attribute value templates" (an expression relative to the source document inside curly brackets):
<rdf:resource id="{foaf:name}"> (...) </rdf:resource>
Finally, use xsl:value-of only to output the text of the result element: <rdf:resource> <xsl:value-of select="normalize-space(gemq:catalogingOrganization/foaf:phone)" /> </rdf:resource>
<xsl:when test="gemq:catalogingOrganization/foaf:homepage"> <xsl:value-of rdf:resource="{normalize-space(gemq:catalogingOrganization/foaf:homepage)}"/></xsl:when> (...) </xsl:template>
[1] XSLT Tutorial http://www.w3schools.com/xsl/
[2] XSL Transformations - from Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/XSLT
[3] XSL Frequently Asked Questions - maintained by Dave Pawson http://www.dpawson.co.uk/xsl/
[4] Jeni's XSLT Pages - Jeni Tennison http://www.jenitennison.com/xslt/index.html
books: [5] Beginning XSLT by Jeni Tennison http://www.amazon.com/gp/product/1861005946/103-9672661-7999067?n=283155
[6] XSLT 2.0 Programmer's Reference, 3rd Edition by Michael Kay http://www.wrox.com/WileyCDA/WroxTitle/productCd-0764569090.html
and reference material: [7] W3C Recommandation - XML Path Language (XPath) Version 1.0 http://www.w3.org/TR/xpath
[8] W3C Recommandation - XSL Transformations (XSLT) Version 1.0 http://www.w3.org/TR/xslt
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XML transformation to RDF, oknam park | Thread | [xsl] How to insert Root Element in, Gary E. Daniels |
Re: [xsl] HTML Tags in XML, andrew welch | Date | RE: [xsl] XSL-FO alignment, Michael Kay |
Month |