[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XML transformation to RDF with XSLT help

Subject: Re: XML transformation to RDF with XSLT help
From: "oknam park" <ponda7777@xxxxxxxxxxx>
Date: Thu, 04 May 2006 06:46:39 +0000
xslt select xsi type
Thanks a lot~~~~

One more question.

In the xml file,

<gemq:catalogingOrganization>
	<foaf:name>Learn North Carolina</foaf:name>
	<foaf:phone>919-962-8888</foaf:phone>
	<foaf:homepage>http://www.learnnc.org</foaf:homepage>
	<foaf:mbox>mailto:mthibault@xxxxxxxxxxx</foaf:mbox>
</gemq:catalogingOrganization>

<gemq:catalogingOrganization>North Carolina Center</gemq:catalogingOrganization>>

So, It allowed to represent with or without foaf.

And I need to transform this to RDF.

I'm kind of stuck now.

Below is my xsl script.

Could you help me one more?

Thanks a lot~~

<xsl:template match="gemq:catalogingOrganization">
<xsl:choose> <xsl:when test="gemq:catalogingOrganization/foaf:name">
<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>
<xsl:when test="gemq:catalogingOrganization/foaf:homepage">
<xsl:value-of rdf:resource="{normalize-space(gemq:catalogingOrganization/foaf:homepage)}"/></xsl:when>
<xsl:when test="gemq:catalogingOrganization/foaf:mbox">
<xsl:value-of select="normalize-space(gemq:catalogingOrganization/foaf:mbox)"/></xsl:when>
<xsl:otherwise>
<gemq:catalogingOrganization><xsl:value-of select="normalize-space(.)"/></gemq:catalogingOrganization>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


Best regards,
Oknam Park



From: "Eric BrC)chemier" <eric.brechemier@xxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  XML transformation to RDF with XSLT help
Date: Wed, 3 May 2006 09:33:51 +0200

Hi Oknam,

First, thank you for the details of your xml input, expected output,
and current status of your xslt stylesheet. You should just add what
gets you stuck, which would help people understand your problem
quicker :)

The typical way of handling three different outputs depending on
different inputs is to write a different template rule (xsl:template)
for each one, with three different corresponding XPath expressions. In
your case, just translate your requirements to XSLT:

I need to transform this to rdf like this
With xsi:type="dcterms:URI"
<rdf:Description>
    <gemq:teachingMethods
rdf:resource="http://purl.org/gem/instance/GEM-TM/#PeerTutoring"/>
  </rdf:Description>

<xsl:template match="gemq:teachingMethods[@xsi:type='dcterms:URI']"> <rdf:Description> <gemq:teachingMethods rdf:resource="{normalize-space(.)}"/> </rdf:Description> </xsl:template>

With xsi:type="gemq:GEM-TM"
<rdf:Description>
<gemq:teachingMethods>
   <gemq:GEM-TM>
     <rdf:value>Thematic approach</rdf:value>
     <rdfs:label>Thematic approach</rdfs:label>
   </gemq:GEM-TM>
</gemq:teachingMethods>
</rdf:Description>

<xsl:template match="gemq:teachingMethods[@xsi:type='gemq:GEM-TM']"> <rdf:Description> <gemq:teachingMethods> <gemq:GEM-TM> <rdf:value>Thematic approach</rdf:value> <rdfs:label>Thematic approach</rdfs:label> </gemq:GEM-TM> </gemq:teachingMethods> </rdf:Description> </xsl:template>

And with just free-text
<rdf:Description>
    <gemq:teachingMethods>MultimediaInstruction</dc:identifier>
  </rdf:Description>

<xsl:template match="gemq:teachingMethods"> (... You get the point ...) </xsl:template>

This last rule will be applied when the two previous ones don't match.
The job of the XSLT processor is to choose the most specific template
matching your input (based on the match attribute), so you generally
don't need to write this kind of "xsl:choose" explicitly.

The problems I expect with the XSLT you wrote are:

- you cannot create attributes before you create the parent element:
your xsl:attribute instructions should appear inside the block
<gemq:teachingMethods>(...)</gemq:teachingMethods>

- the "test" expressions do not match your requirements
(not[@xsi:type] won't match elements with "xsi:type="gemq:GEM-TM")

I hope that helps,
Best regards,

Eric BrC)chemier

On 5/3/06, oknam park <ponda7777@xxxxxxxxxxx> wrote:
Hello.
I'm working on a xml transformation to RDF with XSLT help.

I'm totally very new to XSLT. And It's hard and I'm stuck now. I need your
help.

Here are xml element representation with three ways.
<gemq:teachingMethods
xsi:type='dcterms:URI'>http://purl.org/gem/instance/GEM-TM/#PeerTutoring</gemq:teachingMethods>
<gemq:teachingMethods xsi:type='gemq:GEM-TM'>Thematic
approach</gemq:teachingMethods>
<gemq:teachingMethods>MultimediaInstruction</gemq:teachingMethods>

I need to transform this to rdf like this
With xsi:type="dcterms:URI"
<rdf:Description>
    <gemq:teachingMethods
rdf:resource="http://purl.org/gem/instance/GEM-TM/#PeerTutoring"/>
  </rdf:Description>

With xsi:type="gemq:GEM-TM"
<rdf:Description>
<gemq:teachingMethods>
   <gemq:GEM-TM>
     <rdf:value>Thematic approach</rdf:value>
     <rdfs:label>Thematic approach</rdfs:label>
   </gemq:GEM-TM>
</gemq:teachingMethods>
</rdf:Description>

And with just free-text
<rdf:Description>
    <gemq:teachingMethods>MultimediaInstruction</dc:identifier>
  </rdf:Description>

I did xslt with
<xsl:template match="gemq:teachingMethods">
<xsl:choose>
<xsl:when test="contains(@xsi:type, 'dcterms:URI')">
<xsl:attribute name="rdf:resource">
<xsl:value-of select="normalize-space(.)"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="not[@xsi:type]">
<xsl:attribute name="rdf:resource">
<xsl:value-of select="normalize-space(.)"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<gemq:teachingMethods>
<xsl:value-of select="normalize-space(.)"/>
</gemq:teachingMethods>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


Could you give me some tips or advice?

I appreciate it.

Thanks a lot,

Best regards,
Oknam

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.