[Newbie] for-each in template, or?

J

John Larson

Hi all,


I am trying to construct a simple table from XML files using XSLT. I would
like to put an ID from the document in column 1, and the content of some
elements that maybe repeated in column 2. Can this be done in a template
using a for-each, or should I use a sort of variable, or?

Desired output:

7817471 author1

7817471 author2

7817471 author3

7817472 author1

7817472 author2



the ID of each document would be in /inspec/article/contg/accn

and the repeated elements in e.g., /inspec/article/bibliog/aug/pname

Thanks for any help!

- John
 
M

Martin Honnen

John said:
I am trying to construct a simple table from XML files using XSLT. I would
like to put an ID from the document in column 1, and the content of some
elements that maybe repeated in column 2. Can this be done in a template
using a for-each, or should I use a sort of variable, or?

Desired output:

7817471 author1

7817471 author2

7817471 author3

7817472 author1

7817472 author2



the ID of each document would be in /inspec/article/contg/accn

and the repeated elements in e.g., /inspec/article/bibliog/aug/pname

Can you post the XML you want to process? Based on the above I would
guess you might want
<xsl:for-each select="/inspec/article/bibliog/aug/pname">
<xsl:value-of select="concat(../../../contg/accn, ' ', .,
'
')"/>
</xsl:for-each>
 
J

John Larson

:


Can you post the XML you want to process? Based on the above I would
guess you might want
<xsl:for-each select="/inspec/article/bibliog/aug/pname">
<xsl:value-of select="concat(../../../contg/accn, ' ', .,

</xsl:for-each>



Thanks - it works beautifully! Also on other elements as long I get the
relative path correct.



Can I somehow limit the match on pnames to the ones that have a certain
attribute, e.g., "@order = first"?



- John
 
M

Martin Honnen

John said:
Can I somehow limit the match on pnames to the ones that have a certain
attribute, e.g., "@order = first"?

Sure, simply add a predicate with that condition:
<xsl:for-each select="/inspec/article/bibliog/aug/pname[@order =
'first']">
 
J

John Larson

Sure, simply add a predicate with that condition:
<xsl:for-each select="/inspec/article/bibliog/aug/pname[@order =
'first']">

Thanks - works beautifully! - John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,173
Messages
2,570,937
Members
47,481
Latest member
ElviraDoug

Latest Threads

Top