xslt with multiple values


Johan Lindgren
 

Yes, with this

           <xsl:value-of select= "concat('name:', article/keywords/name)"/>

you're in a for each and the current position does not have that structure so you need to refer to the current item in the loop with a simple .

           <xsl:value-of select= "concat('name:', .)"/>



Johan

Johan Lindgren, TT, 070-6528007

2018-03-19 14:15 GMT+01:00 John Evans john@... [newsml-g2] <newsml-g2@...>:



Hi all,

I am taking an xml file and converting it to NewsMLG2 as best I can.

It started life as a json file and I turned it into an xml file that seems to keep all json properties.

 

I am trying to capture as much metadata as possible.

 

A part of the file is

 

<newsItem>

<article>

.....

<keywords><name>educationname>keywords>

<keywords><name>cheltenhamname>keywords>

<keywords><name>gloucestershire county councilname>keywords>

<section>cheltenham newssection>

article>

newsItem>

 

 

Within my xslt file I have

 

    <subject >

         <xsl:for-each select="article/keywords/name">

           <xsl:attribute name="qcode">

           <xsl:value-of select= "concat('name:', article/keywords/name)"/>

       xsl:attribute>

      xsl:for-each>

    subject>

 

     <subject >

      <xsl:attribute name="qcode">

        <xsl:value-of select= "concat('section:',article/section)"/>

      xsl:attribute>

    subject>

 

The second bit works fine, the first does not, so I get

<subject qcode="name:" />

<subject qcode="section:cheltenham news" />

 

How do I get

 

<subject qcode="name:education" />

<subject qcode="name:cheltenhamn" />

<subject qcode="name:gloucestershire county council" />

<subject qcode="section:cheltenham news" />

 

Many thanks

 

John Evans

Transtel

 





Paul Harman (BLOOMBERG/ LONDON)
 


Brendan Quinn
 

Hi John,

I feel your whole design does not work well.



I’ve created this XSLT:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">

<newsItem>

<xsl:for-each select="//article/keywords">

<subject>

<xsl:attribute name="qcode"><xsl:value-of select="concat('name:', ./name)"/></xsl:attribute>

</subject>

</xsl:for-each>

<subject>

<xsl:attribute name="qcode"><xsl:value-of select="concat('section:',//article/section)"/></xsl:attribute>

</subject>

</newsItem>

</xsl:template>

</xsl:stylesheet>



And it delivers:

<?xml version="1.0" encoding="UTF-8"?>

<newsItem>

<subject qcode="name:education"/>

<subject qcode="name:cheltenham"/>

<subject qcode="name:gloucestershire county council"/>

<subject qcode="section:cheltenham news"/>

</newsItem>



The issues are:

* Using a foreach requires to put the created element inside it, not setting is as a wrapper
* As Johan already showed: inside a foreach the selected node is the “.” node – and you should refer to it
* Aside: “name:gloucestershire county council” is invalid as it includes spaces, must be encoded to %20



Best,

Michael



From: newsml-g2@yahoogroups.com <newsml-g2@yahoogroups.com>
Sent: Monday, March 19, 2018 1:26 PM
To: newsml-g2@yahoogroups.com
Subject: Re: [newsml-g2] xslt with multiple values








Yes, with this



<xsl:value-of select= "concat('name:', article/keywords/name)"/>



you're in a for each and the current position does not have that structure so you need to refer to the current item in the loop with a simple .



<xsl:value-of select= "concat('name:', .)"/>








Johan



Johan Lindgren, TT, 070-6528007



2018-03-19 14:15 GMT+01:00 John Evans john@transtel.com <mailto:john@transtel.com> [newsml-g2] <newsml-g2@yahoogroups.com <mailto:newsml-g2@yahoogroups.com> >:



Hi all,

I am taking an xml file and converting it to NewsMLG2 as best I can.

It started life as a json file and I turned it into an xml file that seems to keep all json properties.



I am trying to capture as much metadata as possible.



A part of the file is



<newsItem>

<article>

.....

<keywords><name>education</name></keywords>

<keywords><name>cheltenham</name></keywords>

<keywords><name>gloucestershire county council</name></keywords>

<section>cheltenham news</section>

</article>

</newsItem>





Within my xslt file I have



<subject >

<xsl:for-each select="article/keywords/name">

<xsl:attribute name="qcode">

<xsl:value-of select= "concat('name:', article/keywords/name)"/>

</xsl:attribute>

</xsl:for-each>

</subject>



<subject >

<xsl:attribute name="qcode">

<xsl:value-of select= "concat('section:',article/section)"/>

</xsl:attribute>

</subject>



The second bit works fine, the first does not, so I get

<subject qcode="name:" />

<subject qcode="section:cheltenham news" />



How do I get



<subject qcode="name:education" />

<subject qcode="name:cheltenhamn" />

<subject qcode="name:gloucestershire county council" />

<subject qcode="section:cheltenham news" />



Many thanks



John Evans

Transtel


John Evans
 

Hi all,

I am taking an xml file and converting it to NewsMLG2 as best I can.

It started life as a json file and I turned it into an xml file that seems to keep all json properties.

 

I am trying to capture as much metadata as possible.

 

A part of the file is

 

<newsItem>

<article>

.....

<keywords><name>educationname>keywords>

<keywords><name>cheltenhamname>keywords>

<keywords><name>gloucestershire county councilname></keywords>

<section>cheltenham newssection>

article>

newsItem>

 

 

Within my xslt file I have

 

    <subject >

         <xsl:for-each select="article/keywords/name">

           <xsl:attribute name="qcode">

           <xsl:value-of select= "concat('name:', article/keywords/name)"/>

       xsl:attribute>

      xsl:for-each>

    subject>

 

     <subject >

      <xsl:attribute name="qcode">

        <xsl:value-of select= "concat('section:',article/section)"/>

      xsl:attribute>

    subject>

 

The second bit works fine, the first does not, so I get

<subject qcode="name:" />

<subject qcode="section:cheltenham news" />

 

How do I get

 

<subject qcode="name:education" />

<subject qcode="name:cheltenhamn" />

<subject qcode="name:gloucestershire county council" />

<subject qcode="section:cheltenham news" />

 

Many thanks

 

John Evans

Transtel

 


John Evans
 

Hi Michael, Paul and Johan

 

Thanks for the responses.

 

The Johan improvement still only returns one value, so I now get

 

<subject qcode="name:gloucestershire county council" />

<subject qcode="section:cheltenham news" />

 

 

I have just tried Michael’s improvement and I can see that I had things in the wrong order.

 

THANKS ALL.

 

 

Paul,

Yes I agree with your comments, and did not fully explain everything.

This is the first part of a coding function that will eventually build a legitimate CV.

I just need to make sure I am capturing the fact that there are three different values of a subject code type identifier, that they happen to call ‘name’.  

I am trying to find out (programmatically) if they do actually have a CV, or if they are just making up keywords.

I am also making use of my software’s ability to automatically search for things it thinks are in a CV, even if the CV is not constructed following correct qcode rules.

 

This is also part of a much larger project that covers a few hundred local newspapers.

 

 

Nice to see you are all still on the ball J

 

John

 

 

 

 

From: newsml-g2@... [mailto:newsml-g2@...]
Sent: 19 March 2018 12:37
To: newsml-g2@...
Subject: Re: [newsml-g2] xslt with multiple values

 

 

This might be a simplified example of course, but I'm not sure if subject/@qcode is a good match for keyword/name, or that 'name' is an appropriate schema alias.

 

'keyword' does exist in the NAR for ad-hoc/folksonomy style tagging.

 

If these are controlled values then subject would be appropriate, and you could use @qcode, but you'll need to URL-encode the values (spaces, amongst other characters, are not valid in qcode values).

 

 

From: newsml-g2@... At: 03/19/18 12:26:08

To: newsml-g2@...
Subject: Re: [newsml-g2] xslt with multiple values

 

Yes, with this

 

           <xsl:value-of select= "concat('name:', article/keywords/name)"/>

 

you're in a for each and the current position does not have that structure so you need to refer to the current item in the loop with a simple .

 

           <xsl:value-of select= "concat('name:', .)"/>

 

 

 

Johan

 

Johan Lindgren, TT, 070-6528007

 

2018-03-19 14:15 GMT+01:00 John Evans john@... [newsml-g2] <newsml-g2@...>:

 

Hi all,

I am taking an xml file and converting it to NewsMLG2 as best I can.

It started life as a json file and I turned it into an xml file that seems to keep all json properties.

 

I am trying to capture as much metadata as possible.

 

A part of the file is

 

<newsItem>

<article>

.....

<keywords><name>education</name></keywords>

<keywords><name>cheltenham</name></keywords>

<keywords><name>gloucestershire county council</name></keywords>

<section>cheltenham news</section>

</article>

</newsItem>

 

 

Within my xslt file I have

 

    <subject >

         <xsl:for-eachselect="article/keywords/name">

           <xsl:attributename="qcode">

           <xsl:value-ofselect= "concat('name:', article/keywords/name)"/>

       </xsl:attribute>

      </xsl:for-each>

    </subject>

 

     <subject >

      <xsl:attributename="qcode">

        <xsl:value-ofselect= "concat('section:',article/section)"/>

      </xsl:attribute>

    </subject>

 

The second bit works fine, the first does not, so I get

<subjectqcode="name:" />

<subjectqcode="section:cheltenham news" />

 

How do I get

 

<subjectqcode="name:education" />

<subjectqcode="name:cheltenhamn" />

<subjectqcode="name:gloucestershire county council" />

<subjectqcode="section:cheltenham news" />

 

Many thanks

 

John Evans

Transtel