xsl-list
[Top] [All Lists]

RE: identifying the specific comments associated with an element

2004-03-26 02:09:50
It's an example of positional grouping.

In XSLT 2.0, you can do

<xsl:for-each-group select="node()" group-ending-with="item">

(an interesting use case for this rarely-used option)

In 1.0, you do

<xsl:for-each select="item">
  <xsl:variable name="gid" select="generate-id(.)"/>
  <xsl:for-each
select="preceding-sibling::comment()[generate-id(following-sibling::item[1])
=$gid]">

Unfortunately this is likely to have O(n^2) performance.

Michael Kay 

# -----Original Message-----
# From: avi paradise [mailto:aparadise(_at_)eyecatching(_dot_)com] 
# Sent: 26 March 2004 02:10
# To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
# Subject: [xsl] identifying the specific comments associated 
# with an element
# 
# I would like to process data that is in the following format.
# 
#  <dataItems>
#       <!-- this is a comment about the first item -->
#       <item name="itemName1">I1</item>
# 
#       <!-- this is a comment about the second item -->
#       <!-- this is a follow on comment for 2nd item -->
#       <item name="itemName2">I2</item>
# 
#       <!-- this is a comment about the third item -->
#       <!-- 3rd item also has an additional comment line -->
#       <item name="itemName3">I3</item>
# 
#       <!-- this is a comment about the fourth item -->
#       <item name="itemName4">I4</item>
#  </dataItems>
# 
# In particular I would like to be able to  process one item at 
# a time as is customarily done with <xsl:apply-templates 
# select="/dataItems/item" />
# 
# What I don't understand how to do is associate  the comments 
# with the appropriate data items.
# For instance, how would I process this data to convert the 
# comments into attributes as follows:
# 
#  <dataItems>
#       <item name="itemName1" comment="this is a comment about 
# the first item">I1</item>
# 
#       <item name="itemName2" comment="this is a comment about 
# the second item. this is a follow on comment for 2nd item">I2</item>
# 
#       <item name="itemName3" comment="this is a comment about 
# the third item. 3rd item also has an additional comment 
# line">I3</item>
# 
#       <item name="itemName4" comment="this is a comment about 
# the fourth item">I4</item>  </dataItems>
# 
# Or how would I select the item whose name is "itemName3" 
# along with it's comments? i.e call <xsl:apply-templates 
# select="/dataItems/item/[(_at_)name = 'itemName3']" /> and within 
# the item template grab the comments
#       <!-- this is a comment about the third item -->
#       <!-- 3rd item also has an additional comment line -->
# 
# 
# Thanks,
# ap
# 
# 
# 
# --+------------------------------------------------------------------
# XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
# You are subscribed as: mhk(_at_)mhk(_dot_)me(_dot_)uk
# To unsubscribe, go to: 
# 
http://lists.mulberrytech.com/unsub.php/xsl-list/mhk(_at_)mhk(_dot_)me(_dot_)uk
# or e-mail: 
# 
<mailto:xsl-list-unsubscribe-mhk=mhk(_dot_)me(_dot_)uk(_at_)lists(_dot_)mulberrytech(_dot_)com>
# --+--
# 



<Prev in Thread] Current Thread [Next in Thread>