xsl-list
[Top] [All Lists]

Re: [xsl] Transforming Learning Object Metadata (LOM) problem.

2006-09-12 02:42:28
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(_at_)nag(_dot_)co(_dot_)uk> 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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--