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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get access to the first preceding comment?

Status
Not open for further replies.

gatwick2002

Programmer
Jun 24, 2004
8
US
My XML (version 1):

[q]
<?xml version="1.0" encoding="utf-8"?>
<w:document xmlns:ve=" xmlns:eek:="urn:schemas-microsoft-com:eek:ffice:eek:ffice" xmlns:r=" xmlns:m=" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp=" xmlns:w10="urn:schemas-microsoft-com:eek:ffice:word" xmlns:w=" xmlns:wne=" <w:body>
<!--7-35|LTD_START--><w:p>
</w:p><!--7-35|LTD_END-->
<!--7-36|LTD_START--><w:p>
<w:r>
<w:t>This is a marketing requirement document.</w:t>
</w:r>
</w:p><!--7-36|LTD_END-->



<w:p>
<w:r w:rsidRPr="00FE6F45">
<w:t>$$$$$ ADDED PARA $$$$$</w:t>
</w:r>
</w:p>


<!--7-37|LTD_START--><w:p>
<w:r>
<w:t>Our objectives with this MRD are several:</w:t>
</w:r>
</w:p><!--7-37|LTD_END-->
</w:body>
</w:document>

[/q]


My XML (version 2):

[q]
<?xml version="1.0" encoding="utf-8"?>
<w:document xmlns:ve=" xmlns:eek:="urn:schemas-microsoft-com:eek:ffice:eek:ffice" xmlns:r=" xmlns:m=" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp=" xmlns:w10="urn:schemas-microsoft-com:eek:ffice:word" xmlns:w=" xmlns:wne=" <w:body>
<!--7-35|LTD_START--><w:p>
</w:p><!--7-35|LTD_END-->
<!--7-36|LTD_START--><w:p>
<w:r>
<w:t>This is a marketing requirement document.</w:t>
</w:r>
</w:p><!--7-36|LTD_END-->
<w:p>
<w:r w:rsidRPr="00FE6F45">
<w:t>$$$$$ ADDED PARA $$$$$</w:t>
</w:r>
</w:p>


<!--7-37|LTD_START--><w:p>
<w:r>
<w:t>Our objectives with this MRD are several:</w:t>
</w:r>
</w:p><!--7-37|LTD_END-->
</w:body>
</w:document>

[/q]


My XML (version 3):

[q]
<?xml version="1.0" encoding="utf-8"?>
<w:document xmlns:ve=" xmlns:eek:="urn:schemas-microsoft-com:eek:ffice:eek:ffice" xmlns:r=" xmlns:m=" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp=" xmlns:w10="urn:schemas-microsoft-com:eek:ffice:word" xmlns:w=" xmlns:wne=" <w:body>
<!--7-35|LTD_START--><w:p>
</w:p><!--7-35|LTD_END-->
<!--7-36|LTD_START--><w:p>
<w:r>
<w:t>This is a marketing requirement document.</w:t>
</w:r>
</w:p><!--7-36|LTD_END-->

<w:p></w:p>

<w:p>
<w:r w:rsidRPr="00FE6F45">
<w:t>$$$$$ ADDED PARA $$$$$</w:t>
</w:r>
</w:p>


<!--7-37|LTD_START--><w:p>
<w:r>
<w:t>Our objectives with this MRD are several:</w:t>
</w:r>
</w:p><!--7-37|LTD_END-->
</w:body>
</w:document>

[/q]

XSL:


[q]
<xsl:stylesheet xmlns:xsl=" xmlns:w=" xmlns:a=" xmlns:eek:="urn:schemas-microsoft-com:eek:ffice:eek:ffice"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:WX=" xmlns:aml=" xmlns:w10="urn:schemas-microsoft-com:eek:ffice:word"
xmlns:wp=" xmlns:r=" xmlns:rs=" xmlns:exsl=" exclude-result-prefixes="exsl"
version="1.0">

<xsl:eek:utput method="xml" encoding="utf-8" indent="no"/>

<xsl:template match="w:p[w:smartTag[@w:element='livetechdocs']/w:smartTagPr/w:attr[@w:name='remap']][count(ancestor::w:tbl)=0]">

<xsl:if test="preceding::node()[normalize-space()][1]">

<xsl:if test="preceding::node()[normalize-space()][1][self::comment()]">
<xsl:message>COMMENT DETECTED: <xsl:value-of select="preceding::node()[normalize-space()][1][self::comment()]"/></xsl:message>
</xsl:if>

</xsl:if>

</xsl:template>

</xsl:stylesheet>
[/q]

How should I make it output COMMENT DETECTED: 7-36|LTD_END ONLY for version 1 & 2?
 
[0] You use preceding axis. You do not expect anything from their descendants, do you not? Hence, I would say, you should just use preceding-sibling axis.

[1] Replace this part.
><xsl:if test="preceding::node()[normalize-space()][1]">
> <xsl:if test="preceding::node()[normalize-space()][1][self::comment()]">
> <xsl:message>COMMENT DETECTED: <xsl:value-of select="preceding::node()[normalize-space()][1][self::comment()]"/></xsl:message>
> </xsl:if>
></xsl:if>

by this.

[tt]<xsl:choose>
<xsl:when test="contains(preceding-sibling::node()[normalize-space()][1][self::comment()],'END')">
<xsl:message>COMMENT DETECTED: <xsl:value-of select="preceding-sibling::node()[normalize-space()][1][self::comment()]"/></xsl:message>
</xsl:when>
<xsl:eek:therwise>
<xsl:message><!-- whatever message you want or nothing --></xsl:message>
</xsl:eek:therwise>
</xsl:choose>[/tt]
 
When you use preceding-sibling it parses in opposite order as following sibling.

Ex.
last(),[2],[1],current(),[1],[2],last()

by default preceding sibling take the first preceding node so take away the [1] and it should work.

I just had problems with this, hope it helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top