Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL problem

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Help,

I have a xml file:

<persons>
<preson no=&quot;1&quot;>
<name>John</name>
<set>1</set>
<say>hello</say>
</preson>
<preson no=&quot;2&quot;>
<name>John</name>
<set>1</set>
<say>hey</say>
</preson>
<preson no=&quot;3&quot;>
<name>Peter</name>
<set>2</set>
<say>hi</say>
</preson>
<preson no=&quot;4&quot;>
<name>Peter</name>
<set>3</set>
<say>yo</say>
</preson>
</persons>
etc...

John from <person no=&quot;1&quot;> and <preson no=&quot;2&quot;> this is the same person from
database. Also <set> from <person no=&quot;1&quot;> and <set> from <person no=&quot;2&quot;>
this is the same <set>. Each person has a few sets, and each set cointains a
few elements <say>.

I don't know how to write an XSL which makes from this exapmle XML next one:

<presons>
<preson>
<name>John</name>
<sets>
<set>1</set>
<says>
<say>hello</say>
<say>hey</say>
</says>
</sets>
</person>
<preson>
<name>Peter</name>
<sets>
<set>2</set>
<says>
<say>hi</say>
</says>
<set>3</set>
<says>
<say>yo</say>
</says>
</sets>
</person>
etc...

--
Artur

 
hmnmnmn..

I dont see how you're going to be able to get useful information out of that.

How can you tell if John is not a different john? and for example peter belongs to two sets, so sets aren't any use in identifying them either, unless that IS how you are identifying different people called peter...?

Please clarify.

However if you are identifying the people via sets, what you need to use is meunchien grouping, and create a key on the &quot;set&quot; tag. see:


hope that helps
 
I don't know what you are trying to archieve but I think this stylesheet might give you a heads start
***************************************************
----------------persons.xml--------------------------
<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;persons.xsl&quot;?>
<persons>
<person no=&quot;1&quot;>
<name>John</name>
<set>1</set>
<say>hello</say>
</person>
<person no=&quot;2&quot;>
<name>John</name>
<set>1</set>
<say>hey</say>
</person>
<person no=&quot;3&quot;>
<name>Peter</name>
<set>2</set>
<say>hi</say>
</person>
<person no=&quot;4&quot;>
<name>Peter</name>
<set>3</set>
<say>yo</say>
</person>
</persons>


----------------persons.xsl--------------------------
<xsl:stylesheet xmlns:xsl=&quot; version=&quot;1.0&quot;>
<xsl:eek:utput method=&quot;xml&quot; indent=&quot;yes&quot; />
<xsl:template match=&quot;/&quot;>
<persons>
<xsl:apply-templates />
</persons>
</xsl:template>
<xsl:template match=&quot;person&quot;>
<xsl:variable name=&quot;name&quot; select=&quot;name&quot; />
<person>
<name>
<xsl:value-of select=&quot;name&quot; />
</name>
<sets>
<xsl:for-each select=&quot;/persons/person[name=$name]&quot;>
<set>
<xsl:value-of select=&quot;set&quot; />
</set>
</xsl:for-each>
</sets>
<says>
<xsl:for-each select=&quot;/persons/person[name=$name]&quot;>
<say>
<xsl:value-of select=&quot;say&quot; />
</say>
</xsl:for-each>
</says>
</person>
</xsl:template>
</xsl:stylesheet>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top