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

Including some child nodes of mixed nodes, but not others 2

Status
Not open for further replies.

newbie404

Programmer
Mar 2, 2004
19
IE
I am trying to present some xml in a browser, using xsl, from a mixed node, so that I include every <inserted> child node, and leave out every <deleted> one. (Yes, I AM trying to create track-changes!).

Is it possible to do this and still have the text in order?

Here is an example of what I want to happen;

I want this node:

<Text>Buyers are someti<deleted>mes referred</deleted> to as owners<inserted>xxvxvxcvcv</inserted>, whereas sellers can be vendors,<deleted> su</deleted>ppliers, or<deleted> contra</deleted>ctors.</Text>

to display in the browser as:

Buyers are someti to as ownersxxvxvxcvcv, whereas sellers can be vendors,ppliers, orctors.

many thanks!
Andy
 
Tricky. This works, but as soon you add nodes with other information you might get into trouble, as this displays any node apart from <deleted>.

Code:
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
 <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>

 <xsl:template match="/">
  <xsl:apply-templates/>
 </xsl:template>

 <xsl:template match="deleted"/>
	
</xsl:stylesheet>
 
That's not a problem, as I am going right down to the node each time. However, I only want to display nodes that have either insertions or deletions make. The report I am generating is a change report, so I had been using -

<xsl:for-each select="Text/deleted">
<div id="textrow">Deletion <br/>
<xsl:value-of select=".."/>
</div>
</xsl:for-each>


<xsl:for-each select="Text/inserted">
<div id="textrow">Insertion: <br/>
<xsl:value-of select=".."/>
</div>
</div></xsl:for-each>

That way, if there was no insertions or deletions nothing would show. If I use the code you gave me I will get the entire text, even if there is no insertion/deletion.

Sorry, I should have been clearer in my original post.

Thanks for the help, and the help with the HTML formatting. I had been bashing my head against the wall with that one!

 
I'm not sure if you got it working now.
Just to be on the safe side:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
 <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
 
 <xsl:template match="/">
  <xsl:apply-templates/>
 </xsl:template>

 <!-- dont ever parse this node: -->
 <xsl:template match="deleted"/>

 <!-- starting from the root-node: just to be sure that no other nodes but the 'Text'-nodes are parsed -->
 <xsl:template match="root">
  <xsl:for-each select="Text[deleted]">
   <div id="textrow">
    Deletion:
    <br/>
    <xsl:apply-templates/>
   </div>
  </xsl:for-each>

  <xsl:for-each select="Text[inserted]">
   <div id="textrow">
    Insertion:
    <br/>
    <xsl:apply-templates/>
   </div>
  </xsl:for-each>
 </xsl:template>

</xsl:stylesheet>
 
Here is another way of achieving the same result
without using a for-each construct.

Code:
<xsl:template match="/">
     <xsl:apply-templates select="//deleted | //inserted" />
</xsl:template>
<xsl:template match="//deleted">
<div id="textrow">Deletion: <br/>
<xsl:value-of select="."/>
</div>
</xsl:template>

<xsl:template match="//inserted">
<div id="textrow">Insertion: <br/>
<xsl:value-of select="."/>
</div>
</xsl:template>
 
Sorry for delay getting back to these replies. I took the end of last week off.

Both versions worked a treat. I went with the first one, as I understand it a bit better. I need to hit the books a bit and get myself better aquainted with xsl. Are there any good online resources/tutorials you'd recommend? Or good books?

thanks a lot for all the help!

Andy
 
Yeah, I've been using w3schools, but they seem to stop after the basics. As soon as you have your cd's sorted out you are on your own! :eek:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top