grouping elements

O

ofuuzo1

Hi,
I have the following xml file which I would like to transform to
another structure:

<person>
<dept>
<gr_name>sale</gr_name>
<gr_id>2<gr_id>
....
<dept>
<name>Peter Pan</name>
<dept>
</person>

<person>
<dept>
<gr_name>production</gr_name>
<gr_id>3<gr_id>
....
<dept>
<name>John John</name>
<dept>
</person>

<person>
<dept>
<gr_name>package</gr_name>
<gr_id>11<gr_id>
....
<dept>
<name>Roy Kemp</name>
<dept>
</person>
......

New xml would look like this:
<sale>Peter Pan</sale>
<production_package_etc>John John<production_package_etc>
<production_package_etc>Roy Kemp<production_package_etc>

I have written some thing like this and it is not working. What is
wrong her?


<xsl:for-each select="//person">
<xsl:if test="//person/dept/gr_id = 1">
<sale> <xsl:value-of select="name" /><sale>
</xsl:if>
</xsl:for-each>

<xsl:for-each select="//person">
said:
< production_package_etc>
</xsl:if>
</xsl:for-each>

Thanks in advance.
 
M

Martin Honnen

I have the following xml file which I would like to transform to
another structure:

<person>
<dept>
^^^^^^
So here is a 'dept' start tag
<gr_name>sale</gr_name>
<gr_id>2<gr_id>
....
<dept>
^^^^^^
And here is another one
<name>Peter Pan</name>
<dept>
^^^^^^
And here is yet another one while there are no matching end tags.
Can you post a well-formed sample? Currently it is not clear how your
input XML looks.

<xsl:for-each select="//person">
<xsl:if test="//person/dept/gr_id = 1">

You need a relative XPath here e.g.
<xsl:if test="dept/gr_id = 1">
but it is even better to write templates e.g.
<xsl:template match="person[dept/gr_id = 1]">
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top