[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: [XSLT 2.0] Using insert-before() to insert a non-a

Subject: RE: [XSLT 2.0] Using insert-before() to insert a non-atomic value
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Sat, 28 Feb 2004 18:13:18 -0000
xslt insert before

# 
# Here I create a variable to hold the sequence of Members:
# 
# <xsl:variable name="members" select="/FitnessCenter/Member"/>
# 
# Here I iterate through the Members and print out their Names:
# 
# <xsl:for-each select="$members">
#        <xsl:value-of select="Name"/>
#        <xsl:text> </xsl:text>
# </xsl:for-each>
# 
# Output: Jeff David Roger
# 
# Now I would like to insert into the member sequence a new member.  Here
# I create a variable containing the new member:
# 
# <xsl:variable name="new-member">
#     <Member level="platinum">
#         <Name>Sally</Name>
#         <Phone>444-1234</Phone>
#         <FavoriteColor>green</FavoriteColor>
#     </Member>
# </xsl:variable>
# 
# Question #1: Is this the correct approach to creating a new Member?  I
# suspect not, but I don't know how else to do it.

This creates a new Member element but it also creates a document node as a
parent of that element. You can avoid creating the document node by writing:

<xsl:variable name="new-member" as="element()">
     <Member level="platinum">
         <Name>Sally</Name>
         <Phone>444-1234</Phone>
         <FavoriteColor>green</FavoriteColor>
    </Member>
</xsl:variable>

# 
# Now, using the insert-before function, I would like to insert this new
# member before the second Member:
# 
# <xsl:variable name="members-plus-new-member"
#               select="insert-before($members,2,$new-member)"/>
# 
# Lastly, I would like to print the Name of each Member in the new
# sequence:
# 
# <xsl:for-each select="$members-plus-new-member">
#        <xsl:value-of select="Name"/>
#        <xsl:text> </xsl:text>
# </xsl:for-each>
# 
# The output that I get is not what I desire:
# 
# Output: Jeff David Roger
# 
# Note that Sally is missing.
# 
# Question #2: What am I doing wrong?  Obviously, I am not understanding
# something fundamental about sequences in XSLT 2.0.  Any clarity on this
# topic would be greatly appreciated.  /Roger
# 
You have added a document node into the sequence, not a Member element, and
the document node does not have a child called "Name".

Michael Kay



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.