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

Re: Transforming Learning Object Metadata (LOM) proble

Subject: Re: Transforming Learning Object Metadata (LOM) problem.
From: "Jaebin Lee" <jaebin.charade@xxxxxxxxx>
Date: Tue, 12 Sep 2006 11:42:09 +0200
lom example
Thank you for the hints.
So i've fixed some of the code and now the problematic part looks like

<xsl:key name="gen-identifier" match="general/l:identifier/*" use="name()"/>

<xsl:template match="l:general">
	<xsl:apply-templates select="l:identifier"/>
</xsl:template>

<xsl:template match="l:identifier">
		<xsl:for-each select="* [ count( . | key( 'gen-identifier', name()
)[1] ) = 1 ] ">
			&lt;FIELD name="<xsl:value-of select="local-name()"/>&gt;<br/>
			<xsl:for-each select="key('gen-identifier', local-name())">
				<xsl:value-of select="current()"/><br/>
			</xsl:for-each>
			&lt;/FIELD&gt;<br/>
		</xsl:for-each>
</xsl:template>

and Here, the reason I'm using key is to group some of the same named
elements in xml and print them in one field.
For example, in the sample below, I'm outputting to field each named
catalog and entry,
with values of all catalogs together, and all entry values under other field.
<general>
 <identifier>
 <catalog>Sample Catalog 1</catalog>
 <entry>Sample Entry 1</entry>
 </identifier>
 <identifier>
 <catalog>Sample Catalog 2</catalog>
 <entry>Sample Entry 2</entry>
 </identifier>
....
and output is..
<FIELD name="catalog>
Sample Catalog 1
Sample Catalog 2
</FIELD>
<FIELD name="entry>
Sample Entry 1
Sample Entry 2
</FIELD>

<xsl:for-each select="* [ count( . | key( 'gen-identifier', name()
)[1] ) = 1 ] ">
above line was to print out only one <Field> for same named elements.
and I used muenchen method for grouping the same named elements
because it was handy to use. Should I avoid using keys in this
situation?

and Also by the way, How can I print new line in new xml file after
conversion? to state this differently, what should I put in the xsl
file to print new line like <br/> in new xml file?

Thank you!
-Jaebin
On 9/12/06, David Carlisle <davidc@xxxxxxxxx> wrote:

<xsl:key name="gen-identifier" match="//l:general/identifier/*" use="name()"/>


If you need this key you need l:identifier not identifier.

However I strong;y suspect that you don't need a key at all, the useage
here is very strange.
Match patterns never need to start with // (it makes no difference at
all whether the // is there)  Also normally (almost always) you don't
want to use name() in a stylesheet as that depends on namespace prefixes
which should not be ddepended on. an xpath selecting l:title
will match title in the lom namespaec whatever prefix (or no
prefix) is used in the source document, but a text of
name()='title' which is effectively what you have here will only match
unprefixed elements with name title, and will match them whatever
namespace they are in.

<xsl:template match="l:identifier | l:title | l:description |
l:keyword | l:version | l:source">
        <xsl:choose>
           <xsl:when test="name() = 'identifier' ">

Why make a template matching 6 different elements only to have to choose
between them? If you must do this, as mentioned above dontt use name()
use
 test="self::identifier"
but it usually one would write
<xsl:template match="l:itentifier">
 ....

                <xsl:for-each select="* [ count( . | key( 'gen-identifier', name()
)[1] ) = 1 ] ">

I have no idea what you are trying to test here so i can;'t suggest an
alternative but a key indexes the whole document, so this looks at each
child of teh current node and then looks up the name of the child and
sees if there is a child of that name anywhere in the document (which
there must be, as there is one as the child of teh current node)
                        &lt;FIELD n
Do you want to generate text here or an element? If you want to generate
an element don't use    &lt;FIELD  use
<FIELD>

David

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

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-2013 All Rights Reserved.