homepage Welcome to WebmasterWorld Guest from 54.237.125.89
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
Nesting complex non-nested paths
i.e. parsing word's XML into something useable
RandorWay




msg:3975202
 7:38 pm on Aug 19, 2009 (gmt 0)

I'm trying to figure out how to parse a microsoft word XML file into something nested and usable for our other applications. The structure right now I'm going for is:

<Quiz>
<Question>
<question>...</question>
<answer>...</answer
<answer>...</answer>
</Question>
...
</Quiz>

I've managed to get it non-nested so far, but that's not too handy.

Can anyone point me to some tutorials or provide some advice?

I've found sites like this:
[biglist.com...]
and
[aspn.activestate.com...]

But I can't seem to get the same things to apply to the microsoft xml format. Le sigh.

Here is the current XSL file (not parsing through xsltproc):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">
<Quiz>
<xsl:for-each select="w:document/w:body/w:p">
<xsl:if test="./w:pPr/w:pStyle[@w:val='Question']">
<question>
<xsl:for-each select="./w:r/w:t">
<xsl:value-of select="." />
</xsl:for-each>
<xsl:apply-template select="self::./w:p" />
</question>
</xsl:if>
</xsl:for-each>
</Quiz>
</xsl:template>

<xsl:template match="w:p">
<xsl:if test="./w:pPr/w:pStyle[@w:val='Answers']">
<answer>
<xsl:for-each select="./w:r/w:t">
<xsl:value-of select="." />
</xsl:for-each>
</answer>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

This is the example xml file I'm trying to parse:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?xml-stylesheet type="text/xsl" href="test.xsl"?>
<w:document ve:Ignorable="mv" ve:PreserveAttributes="mv:*" xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main" xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing">
<w:body>
<w:p w:rsidR="006F3779" w:rsidRDefault="006F3779" w:rsidP="006F3779">
<w:pPr>
<w:pStyle w:val="Question"/>
</w:pPr>
<w:r>
<w:t xml:space="preserve">Question </w:t>
</w:r>
<w:proofErr w:type="spellStart"/>
<w:r>
<w:t>Question</w:t>
</w:r>
<w:proofErr w:type="spellEnd"/>
</w:p>
<w:p w:rsidR="006F3779" w:rsidRDefault="006F3779"/>
<w:p w:rsidR="006F3779" w:rsidRDefault="006F3779" w:rsidP="006F3779">
<w:pPr>
<w:pStyle w:val="ListParagraph"/>
<w:numPr>
<w:ilvl w:val="2"/>
<w:numId w:val="3"/>
</w:numPr>
</w:pPr>
<w:r>
<w:t>Answer</w:t>
</w:r>
</w:p>
<w:p w:rsidR="006F3779" w:rsidRDefault="006F3779" w:rsidP="006F3779">
<w:pPr>
<w:pStyle w:val="ListParagraph"/>
<w:numPr>
<w:ilvl w:val="2"/>
<w:numId w:val="3"/>
</w:numPr>
</w:pPr>
<w:r>
<w:t>Answer</w:t>
</w:r>
</w:p>
<w:p w:rsidR="006F3779" w:rsidRDefault="006F3779" w:rsidP="006F3779">
<w:pPr>
<w:pStyle w:val="ListParagraph"/>
<w:numPr>
<w:ilvl w:val="2"/>
<w:numId w:val="3"/>
</w:numPr>
</w:pPr>
<w:r>
<w:t>Answer</w:t>
</w:r>
</w:p>
<w:p w:rsidR="006F3779" w:rsidRDefault="006F3779"/>
<w:p w:rsidR="006F3779" w:rsidRDefault="006F3779" w:rsidP="006F3779">
<w:pPr>
<w:pStyle w:val="Question"/>
</w:pPr>
<w:r>
<w:t>Question</w:t>
</w:r>
</w:p>
<w:p w:rsidR="006F3779" w:rsidRDefault="006F3779"/>
<w:p w:rsidR="006F3779" w:rsidRDefault="006F3779" w:rsidP="006F3779">
<w:pPr>
<w:pStyle w:val="ListParagraph"/>
<w:numPr>
<w:ilvl w:val="2"/>
<w:numId w:val="2"/>
</w:numPr>
</w:pPr>
<w:proofErr w:type="spellStart"/>
<w:r>
<w:t>Answerwer</w:t>
</w:r>
<w:proofErr w:type="spellEnd"/>
</w:p>
<w:p w:rsidR="00967CCA" w:rsidRDefault="006F3779" w:rsidP="006F3779">
<w:pPr>
<w:pStyle w:val="ListParagraph"/>
<w:numPr>
<w:ilvl w:val="2"/>
<w:numId w:val="2"/>
</w:numPr>
</w:pPr>
<w:proofErr w:type="spellStart"/>
<w:r>
<w:t>Ansdwer</w:t>
</w:r>
<w:proofErr w:type="spellEnd"/>
<w:r>
<w:tab/>
</w:r>
</w:p>
<w:sectPr w:rsidR="00967CCA" w:rsidSect="00967CCA">
<w:pgSz w:w="12240" w:h="15840"/>
<w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="708" w:footer="708" w:gutter="0"/>
<w:cols w:space="708"/>
</w:sectPr>
</w:body>
</w:document>

 

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved