Click to See Complete Forum and Search --> : [RESOLVED] Help with XML / XPATH query


r0k3t
05-12-2009, 11:03 AM
Hi there,

Sorry for the vague title, I am having trouble finding the answer to this because I don't believe I am even able to phrase the question just right. Maybe if I explain someone can point me in the right direction. This is what I have in my XSLT


<xsl:if test="w:p/w:pPr/w:pStyle/@w:val='TABLEHEADINGALLCAPS'">
<xsl:value-of select="w:p/w:r/w:t"/>
</xsl:if>


That actually works but this is the problem, there are multiple instances of the w:p/w:r/w:t element, that value-of line always gets the first one, that is not what I want. What I want it the is - and correct me if I am wrong, the w:r that is a sibling of w:pPr as they both share the same parent, in this case w:p...

At any rate - thank you for you input, I am very new to XSLT and appreciate your help.

r0k3t
05-12-2009, 11:09 AM
Opps - let me post you some sample XML

<w:p w:rsidR="00480995" w:rsidRPr="00B150B3" w:rsidRDefault="00480995" w:rsidP="00DD5226">
<w:pPr>
<w:pStyle w:val="TABLENAME"/>
</w:pPr>
<w:bookmarkStart w:id="16" w:name="_Toc227993904"/>
<w:r>
<w:t>Summary Table</w:t>
</w:r>
<w:bookmarkEnd w:id="16"/>
</w:p>
<w:p w:rsidR="00480995" w:rsidRPr="00B150B3" w:rsidRDefault="00480995" w:rsidP="00DD5226">
<w:pPr>
<w:pStyle w:val="TableHeading"/>
</w:pPr>
</w:p>
<w:p w:rsidR="00480995" w:rsidRDefault="00480995" w:rsidP="00DD5226">
<w:pPr>
<w:pStyle w:val="TABLEHEADINGALLCAPS"/>
</w:pPr>
<w:r>
<w:t>Product Market Demand</w:t>
</w:r>
</w:p>


What I am trying to do is get both the first and second w:t elements, I keep getting the first one twice.

thanks!

dmboyd
05-12-2009, 11:43 AM
A for-each loop in combination with a modification of your test and value might work:
<xsl:for-each select="w:p">
<xsl:if test="w:pPr/w:pStyle/@w:val='TABLEHEADINGALLCAPS'">
<xsl:value-of select="w:r/w:t" />
</xsl:if>
</xsl:for-each>

Assuming there aren't multiple w:pPr elements in a single w:p element and there aren't multiple w:r elements in a single w:p element, that should work though I can't make any guarantees since it is untested.

r0k3t
05-12-2009, 01:51 PM
Thank you! Excellent idea - that worked...