> Ah rats! But thank you so much for your time, also Sean and Isaac. I'll
> probably go with Sean's approach - mostly because I can understand it
> immediately.
>
> Now I have to figure out how to delete nodes... More later (probably).
No worries... Seans approach had occurred to me also, but I use XSLT
with such frequency that I probably tend in that direction first. So
it's not like my suggestion had anything to do with performance or
anything. I have no idea which would be more efficient. :)
The XPath portion of both solutions is essentially the same -- or at
least pretty similar. In sean's case, the xpath (//nodename) is starting
at the root of the xml document and finding any node matching nodename,
irrespective of how deeply it's nested in the document (that's what the
// indicates).
I'll give you a brief explanation of the XSL just to give you a taste of
how it works for comparison.
In my case because I was using XSLT I knew that it would need to copy
all the nodes in your xml packet, so I started with that
<xsl:template match="*">
Then I made a copy of the node
<xsl:copy>
and its attributes
<xsl:copy-of select="@*" />
and its children (this line tells it to start over at the beginning xsl:match
tag for each child node, similar to the way you might build a tree by
creating a recursive function in CFML)
<xsl:apply-templates />
and then since I was copying all the nodes, I checked to see if we
needed to add the live attribute for the current node using the XSL
equivalent of a <cfswitch> tag
<xsl:choose>
and looped over the ones to update
<cfloop index="i" list="#idlist#">
and inserted the <cfcase> equivalent for each node
<xsl:when test="name()='nodename' and @id='#i#'">
and for nodes found in the id list, I added the live attribute
<xsl:attribute name="live">true</xsl:attribute>
so that's how we end up at the main body of my example:
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:choose>
<cfloop index="i" list="#idlist#">
<xsl:when test="name()='nodename' and @id='#i#'">
<xsl:attribute name="live">true</xsl:attribute>
<xsl:when>
</cfloop>
</xsl:choose>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
Mingling the cfloop with the xslt here is basically similar to building
a javascript switch-case statement with ColdFusion. Or really any
javascript, but choose-when is the xsl equivalent of switch-case
Also actually, part of the reason for this breif tutorial is because you
mentioned deletes and personally I think using xmlSearch for deletions
is more challenging (although I do believe it's possible). In the case
of the example above, to delete you would just remove the xsl:choose and
the associated cfloop and use an xsl:if tag around the xsl:copy tag so
that nodes only get coppied when the if evaluates true. You may or may
not find XSL easier for the deletes -- but you'll have to judge that for
yourself. :)
--
s. isaac dealey ^ new epoch
isn't it time for a change?
ph: 503.236.3691
http://onTap.riaforge.org
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:295459
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4