Jump to content
Woiz

getting different attributes with same name

Recommended Posts

Hi all!

 

I'm trying to redesign a xml-File via a xslt-Stylesheet and somehow it doesn't do, what I want it to, so...

 

The structure of my xml-file is basically like this:

<root><text><articletitle/><date/><content><p><p>...</content></text><text><articletitle>...</text></root>

So, the xml-file consists of several articles which are contained within the <text /> tags. Each article has several meta-information as for example the <articletitle/> and <date/>. The <content> tags include the actual text of the article.

 

What I would like to do, is rewrite the meta-info as an attribute, so the new xml-file structure looks like this:

<root><text articletitle="This is a title" date="This is a date"><content><p>...</content></text><text articletitle="This is another title" date="This is another date"><content><p>...</content></text></root>

What I managed to do, is get the correct structure, however, the title and date seem to be always the one of the first article.

 

Here's an excerpt of my xsl-stylesheet:

<xsl:template match="/"><root><xsl:for-each select="//root/text"><text> <xsl:attribute name="articletitle"><xsl:value-of select="normalize-space(//root/text/articletitle)"/></xsl:attribute> <xsl:attribute name="date"><xsl:value-of select="normalize-space(//root/text/date)"/></xsl:attribute> <xsl:apply-templates/></text></xsl:for-each> </root></xsl:template>
What I thought I did, was to tell it to run through all the nodes at "root/text" and apply the attributes. But as I said before, it does generate the correct structure for each article, but just enters the information of the first article under "articletitle" and "date".
I'd very much appreciate your help.
CheersWoiz

Share this post


Link to post
Share on other sites

I solved the problem on my own.

 

Somehow it just works, if I create a template for each attribute without any use of the "for-each" function. Bit unsexy but works.

 

Thanks anyway

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...