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

using xsl:if and copying a document into another

Status
Not open for further replies.

ronsig

Programmer
May 24, 2001
54
0
0
IL
H!
I have two problems I really need your help with:

The first is:

If my xml file holds a list of nodes like this:

Code:
<Message>
<text>Text of message comes here</text>
<type>Private</type>
<time>23050:11034</time>
</Message>

and in my xsl file I have the following:

<xsl:for-each select=&quot;Messages/Message&quot;><tr bgcolor=&quot;blue&quot;> 
<td><input type=&quot;checkbox&quot; onClick=&quot;CheckIfAll();&quot;></input></td>
<td> <xsl:value-of select=&quot;time&quot;/></td>
<td> <xsl:value-of select=&quot;text&quot;/></td>
</tr>
How can I use <xsl:if> (or some other way) to check the value of the <type> field and if it's value isn't &quot;Private&quot; to change the 'bgcolor' attribute from &quot;blue&quot; to &quot;red&quot;?

the second is:

If I have a DOM_Document variable (in c++) and want to take its entire content and insert it into another document, ow is this done?

I hope I get a response quickly, this stuff's urgent!

 
In answer to your first question, the following should do the trick (untested)...

<xsl:for-each select=&quot;Messages/Message&quot;>
<tr>
<xsl:attribute name=&quot;color&quot;>
<xsl:choose>
<xsl:when test=&quot;text/text()='private'&quot;>
red
</xsl:when>
<xsl:eek:therwise>
blue
</xsl:eek:therwise>
</xsl:choose>
</xsl:attribute>
<td>
<input type=&quot;checkbox&quot; onClick=&quot;CheckIfAll();&quot; />
</td>
<td><xsl:value-of select=&quot;time&quot;/></td>
<td><xsl:value-of select=&quot;text&quot;/></td>
</tr>
</xsl:foreach>

And for the second question...I use java as opposed to C++ but the principles should be the same...

Get the document (root) node of the Document you want to copy in to the new document.

Find the node in the new document that will be the imported documents parent

Then import the document node into that parent.

In java it looks like this...

//----------------------------------------------------------------
// Import a document into an existing DOM tree
//----------------------------------------------------------------
public Element importDocument ( Document parent, Document foreign )
{
Element elemFor = foreign.getDocumentElement();
Element elemPar = parent.getDocumentElement();
if (( elemPar != null ) && ( elemFor != null )) {
Node impNode = parent.importNode((Node)elemFor, true);
elemPar.appendChild( (Element)impNode );
return (Element)impNode;
}
return null;
}

Good Luck
-Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top