|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
XML To TXT help!
Hello I'm new to xml and xsl and I need some help. I have xml file like this
<?xml version="1.0" encoding="UTF-8"?> <OPIT> <SYNSET> <ID>ENG171-01534425-n</ID> <POS>n</POS> <SYNONYM> <LITERAL>kkkkkkk<SENSE>1</SENSE> </LITERAL> <LITERAL>hhhhhhhh<SENSE>1</SENSE> </LITERAL> <LITERAL>lllllllll<SENSE>1</SENSE> </LITERAL> </SYNONYM> <LNOTE>ENG171-01150487-n<ILR>hypernym</ILR> </LNOTE> <TYPE>kjhggsgsgsggs</TYPE> <RILR>DCMB TEAM 2003/05/23</RILR> <BCS>1</BCS> </SYNSET> <SYNSET> ....... </SYNSET> I have to extract to .txt file information for ID(tab)LITERAL(without <sense>)tab LITERAL... ID LITERAL LITERAL LITERAL ...(new line) ID ....... for all SYNSETs Please if anyone can help me. Tanx a lot! |
|
#2
|
||||
|
||||
|
Where's your xsl?
__________________
mr... mike.rusaw@realpage.com RalPage, Inc. "I have made this letter longer than usual, only because I have not had the time to make it shorter." - Blaise Paschal |
|
#3
|
|||
|
|||
|
Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:for-each select="//SYNSET"> <xsl:value-of select="ID"/><xsl:text>& #9;</xsl:text> <xsl:for-each select="SYNONYM/LITERAL"> <xsl:value-of select="text() |* [not(self::SENSE)]"/> <xsl:text>& #9;</xsl:text> </xsl:for-each> <xsl:text>& #13;</xsl:text> </xsl:for-each> </xsl:template> </xsl:stylesheet> Remove the space between & and # for the 3 entities in the above code. Last edited by mulligh : July 29th, 2003 at 01:08 PM. |
|
#4
|
||||
|
||||
|
Here is my solution for you. (**I couldn't get it to work witho your existing xml data structure.) I hope this helps. (**Remember to remove the space in & #9; / & #13;)
Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:for-each select="//SYNSET"> <xsl:value-of select="ID"/><xsl:text>& #9;</xsl:text> <xsl:for-each select="SYNONYM/LITERAL"> <xsl:value-of select="concat(text(), '& #9;')"/> </xsl:for-each> <xsl:text>& #13;</xsl:text> </xsl:for-each> </xsl:template> </xsl:stylesheet> Code:
<?xml version="1.0" encoding="UTF-8"?> <OPIT> <SYNSET> <ID>ENG171-01534425-n</ID> <POS>n</POS> <SYNONYM> <LITERAL SENSE="1">kkkkkkk</LITERAL> <LITERAL SENSE="1">hhhhhhhh</LITERAL> <LITERAL SENSE="1">lllllllll</LITERAL> </SYNONYM> <LNOTE>ENG171-01150487-n <ILR>hypernym</ILR> </LNOTE> <TYPE>kjhggsgsgsggs</TYPE> <RILR>DCMB TEAM 2003/05/23</RILR> <BCS>1</BCS> </SYNSET> <SYNSET> <ID>ENG171-01534425-n1</ID> <POS>n1</POS> <SYNONYM> <LITERAL SENSE="2">kkkkkkk1</LITERAL> <LITERAL SENSE="2">hhhhhhhh1</LITERAL> <LITERAL SENSE="2">lllllllll1</LITERAL> </SYNONYM> <LNOTE>ENG171-01150487-n1 <ILR>hypernym1</ILR> </LNOTE> <TYPE>kjhggsgsgsggs1</TYPE> <RILR>DCMB TEAM 2003/05/231</RILR> <BCS>1</BCS> </SYNSET> <SYNSET> <ID>ENG171-01534425-n2</ID> <POS>n2</POS> <SYNONYM> <LITERAL SENSE="3">kkkkkkk2</LITERAL> <LITERAL SENSE="3">hhhhhhhh2</LITERAL> <LITERAL SENSE="3">lllllllll2</LITERAL> </SYNONYM> <LNOTE>ENG171-01150487-n2 <ILR>hypernym2</ILR> </LNOTE> <TYPE>kjhggsgsgsggs2</TYPE> <RILR>DCMB TEAM 2003/05/232</RILR> <BCS>2</BCS> </SYNSET> </OPIT> Last edited by mrusaw : July 29th, 2003 at 02:25 PM. |
|
#5
|
|||
|
|||
|
Tanx mrusaw, tanx mulligh they are both work.
|
|
#6
|
|||
|
|||
|
Tanx mrusaw, tanx mulligh they are both work.
|
|
#7
|
||||
|
||||
|
mulligh - i was wondering if you have a reference for the character strings (ie. '& #9;'). I have been looking for one for a while.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XML To TXT help! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|