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

Merging data based on attributes, revisited

Subject: Merging data based on attributes, revisited
From: "Bob Portnell" <simply.bobp@xxxxxxxxx>
Date: Thu, 24 Aug 2006 09:27:13 -0700
k3 text
Okay, one more elaboration.

Processing this SVG ...
======================================================================
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<?xml-stylesheet
	type="text/xsl"
	href="newtest.xsl"?>

<svg xmlns="http://www.w3.org/2000/svg"
	
	contentStyleType="text/css"
	contentScriptType="text/ecmascript"
	version="1.1" zoomAndPan="magnify"
	preserveAspectRatio="xMidYMid meet"
	width="100%" height="100%">
	
	<defs/>
	
	<desc>
		Test Page
	</desc>
	
<!-- TEXT ELEMENTS -->
	<g font-family="Arial" font-size="24">
		<!-- DOCUMENT TITLE -->
		<text><tspan x="400" y="60" text-anchor="middle">Test Page</tspan></text>
	</g>
	
	<g font-family="Arial" font-size="8" text-anchor="middle" id="k1">
		<text x="80" y="140">element phase</text>                    <!--
Here's the difference -->
	</g>
	
	<g font-family="Arial" font-size="8" text-anchor="middle" id="k2">
		<text x="80" y="220">element phase</text>
	</g>
	
	<g font-family="Arial" font-size="8" text-anchor="middle" id="k3">
		<text x="80" y="300">element phase</text>
	</g>

<!-- GRAPHIC ELEMENTS -->

	<g fill="none" stroke="black" stroke-width="2">
		<rect x="40" y="120" width="80" height="50" pointer-events="all"
visibility="visible" />
	</g>

	<g fill="none" stroke="black" stroke-width="2">
		<rect x="40" y="200" width="80" height="50" pointer-events="all"
visibility="visible" />
	</g>

	<g fill="none" stroke="black" stroke-width="2">
		<rect x="40" y="280" width="80" height="50" pointer-events="all"
visibility="visible"/>
	</g>

</svg>

The data I want to pull in is the same...
=========================================
<?xml version="1.0" encoding="UTF-8"?>

<test>
	<data id="k3">
		<element>Tritium</element>
		<phase>plasma</phase>
	</data>
	<data id="k2">
		<element>Deuterium</element>
		<phase>solid</phase>
	</data>
	<data id="k1">
		<element>Hydrogen</element>
		<phase>gas</phase>
	</data>
</test>

The desired result will put the data items into the SVG with a space
between, thus:
=====================================================================================
	<g font-family="Arial" font-size="8" text-anchor="middle" id="k1">
		<text x="80" y="140">Hydrogen gas</text>
	</g>
	
	<g font-family="Arial" font-size="8" text-anchor="middle" id="k2">
		<text x="80" y="220">Deuterium solid</text>
	</g>
	
	<g font-family="Arial" font-size="8" text-anchor="middle" id="k3">
		<text x="80" y="300">Tritium plasma</text>
	</g>

Here's the Carlisle-improved stylesheet, botched by me.
=======================================================================================
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
              xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
              xmlns="http://www.w3.org/2000/svg"
              xmlns:svg="http://www.w3.org/2000/svg"
              exclude-result-prefixes="svg"
              >

<!-- copies all nodes/attributes into result tree unchanged -->
<xsl:template match="@*|node()">
  <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="svg:text[.=('element phase')]">
<text>
  <xsl:copy-of select="@*"/>
  <xsl:value-of select="key(element,../@id,doc('textsrc.xml'))"/>
  <xsl:text> </xsl:text>
  <xsl:value-of select="key(phase,../@id,doc('textsrc.xml'))"/>
</text>
</xsl:template>

<xsl:key name="element" match="element" use="../@id"/>
<xsl:key name="phase" match="phase" use="../@id"/>


</xsl:stylesheet> =====================================================================================

This declines to generate any output under Saxon, so I've
misunderstood something and thoroughly. Advice and clewbats welcome.

BobP
simply.bobp@xxxxxxxxx

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.