help! new to xslt

  • Thread starter timothy ma and constance lee
  • Start date
T

timothy ma and constance lee

Sirs/Madam

I am new to xslt but got a trouble

I get the xml messgae like

<message>
<docList>
<docSet>1</docSet>
<docTp>A1/docTp>
<docSet>1</docSet>
<docTp>B1</docTp>
<docSet>2</docSet>
<docTp>A2</docTp>
<docSet>1</docSet>
<docTp>C1</docTp>
<docSet>2</docSet>
<docTp>B2</docTp>

I need to have xslt to make html like

DocSet 1
Doc Tp = A1
Doct Tp = B1
Doc Tp = C1

DocSet2
DocTp = A2
......

Please suggest
</docList>
 
M

Mukul Gandhi

This is a grouping problem, and can be solved using the Muenchian
technique -

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:eek:utput method="html" indent="yes" />

<xsl:key name="by-docSet" match="docSet" use="." />

<xsl:template match="/message">
<html>
<head>
<title/>
</head>
<body>
<table>
<xsl:for-each select="docList/docSet[generate-id(.) =
generate-id(key('by-docSet', .)[1])]">
<tr>
<td>
DocSet
</td>
<td>
<xsl:value-of select="." />
</td>
</tr>
<xsl:for-each select="key('by-docSet', .)">
<tr>
<td>
Doc Tp =
</td>
<td>
<xsl:value-of select="following-sibling::docTp[1]" />
</td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

Regards,
Mukul
 
W

William Park

timothy ma and constance lee said:
Sirs/Madam

I am new to xslt but got a trouble

I get the xml messgae like

<message>
<docList>
<docSet>1</docSet>
<docTp>A1/docTp>
<docSet>1</docSet>
<docTp>B1</docTp>
<docSet>2</docSet>
<docTp>A2</docTp>
<docSet>1</docSet>
<docTp>C1</docTp>
<docSet>2</docSet>
<docTp>B2</docTp>

I need to have xslt to make html like

DocSet 1
Doc Tp = A1
Doct Tp = B1
Doc Tp = C1

DocSet2
DocTp = A2
.....

Please suggest
</docList>

Off topic... but if you have Expat XML parser (www.libexpat.org) and my
patched Bash shell (http://freshmeat.net/projects/bashdiff/),

func () { # Usage: func data
case ${XML_ELEMENT_STACK[1]} in
docTp) echo "$docSet $1" ;;
docSet) docSet=$1 ;;
esac
}
xml -d func "<message> ... </message>"

you will get

1 A1
1 B1
2 A2
1 C1
2 B2

I'll leave it as homework for you to convert to the format you want.
 

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
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top