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

unparsed-text and nodes by position

Subject: unparsed-text and nodes by position
From: Brian Newman <brian.newman@xxxxxxxxxxx>
Date: Thu, 24 Dec 2009 11:42:04 -0500
 unparsed-text and nodes by position
If I've got data that looks like

|Family|Tom|Mary|Bobby|Suzie|
|Family|Mark|Nancy|Alex|Mary|
|Family|Don|Patty|Brian|Jo

And I have a transform which looks like this

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:template match="/">
		<root>
			<xsl:if
test="unparsed-text-available('file://BNEWMAN/Users/bnewman/Desktop/test.txt'
)">
				<xsl:variable name="datafile"
select="unparsed-text('file://BNEWMAN/Users/bnewman/Desktop/test.txt')"/>
				<xsl:for-each select="tokenize(normalize-space($datafile), '[|]Family')">
					<rootpart>
						<xsl:for-each select="tokenize(.,'[|]')">
							<xsl:choose>
								<xsl:when test=".[position()=1]">
									<father>
										<xsl:value-of select="."/>
									</father>
								</xsl:when>
								<xsl:when test=".[position()=2]">
									<mother>
										<xsl:value-of select="."/>
									</mother>
								</xsl:when>
								<xsl:when test=".[position()=3]">
									<child>
										<xsl:value-of select="."/>
									</child>
								</xsl:when>
							</xsl:choose>
						</xsl:for-each>
					</rootpart>
				</xsl:for-each>
			</xsl:if>
		</root>
	</xsl:template>
</xsl:stylesheet>

I am expecting to get a result which looks like this
<root xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<rootpart/>
	<rootpart>
		<father>Tom</father>
		<mother>Mary</mother>
		<child>Bobby</child>
	</rootpart>
	<rootpart>
		<father>Mark</father>
		<mother>Nancy</mother>
		<child>Alex</child>
	</rootpart>
	<rootpart>
		<father>Don</father>
		<mother>Patty</mother>
		<child>Brian</child>
	</rootpart>
</root>

But I'm getting results which look like this

<root xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<rootpart/>
	<rootpart>
		<firstnode>Tom</firstnode>
		<firstnode>Mary</firstnode>
		<firstnode>Bobby</firstnode>
		<firstnode>Suzie</firstnode>
		<firstnode> </firstnode>
	</rootpart>
	<rootpart>
		<firstnode>Mark</firstnode>
		<firstnode>Nancy</firstnode>
		<firstnode>Alex</firstnode>
		<firstnode>Mary</firstnode>
		<firstnode> </firstnode>
	</rootpart>
	<rootpart>
		<firstnode>Don</firstnode>
		<firstnode>Patty</firstnode>
		<firstnode>Brian</firstnode>
		<firstnode>Jo</firstnode>
	</rootpart>
</root>

Can someone help me understand why?

Btw, this is the Altova engine.
(I've been web surfing to figure out how to get Saxon 9 to integrate with
XmlSpy on a Windows machine)

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.