Jump to content

getting different attributes with same name


Woiz

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
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...