Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 22nd, 2011, 03:45 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Again, please define what you mean by 'not working'.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old February 22nd, 2011, 03:49 PM
Authorized User
 
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

for-each loop for stateList/state is not finding the context. I tried apply the template, later i put in the loop. Either case, its not finding the context and writing an empty tags except the first iteration.

I did remove the declaration and now the output is clean with out namespace

Last edited by chilly; February 22nd, 2011 at 04:11 PM..
 
Old February 22nd, 2011, 06:42 PM
Authorized User
 
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have everything working with the following code

Except the header before /ematrix/businessObject, i have the following values.
Code:
<creationProperties>
<release>V6R2009x.HF29(13.0.0.0)</release>
<datetime>2011-02-17T02:41:20Z</datetime>
<event>export</event>
<dtdInfo>&ematrixProductDtd;</dtdInfo>
</creationProperties>
These are getting written to the output. How do i remove these with out writing to an XML to the target.


Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/ematrix/businessObject">
		<xsl:element name="{translate(objectType,' ','')}">
			<Type>
				<xsl:value-of select="objectType"/>
			</Type>
			<Name>
				<xsl:value-of select="objectName"/>
			</Name>
			<revision>
				<xsl:value-of select="objectRevision"/>
			</revision>
			<vault>
				<xsl:value-of select="vaultRef"/>
			</vault>
			<owner>
				<xsl:value-of select="owner/userRef"/>
			</owner>
			<description>
				<xsl:value-of select="description"/>
			</description>
			<originated>
				<xsl:value-of select="creationInfo/datetime"/>
			</originated>
			<modified>
				<xsl:value-of select="modificationInfo/datetime"/>
			</modified>
			<policy>
				<xsl:value-of select="policyRef"/>
			</policy>
			<xsl:for-each select="attributeList/attribute">
				<xsl:call-template name="attribute"/>
			</xsl:for-each>
			<states>
				<xsl:for-each select="stateList/state">
					<xsl:call-template name="state"/>
				</xsl:for-each>
			</states>
			<xsl:if test="fromRelationshipList">
				<fromRelationship>
					<xsl:for-each select="fromRelationshipList/relationship">
						<xsl:call-template name="relation"/>
					</xsl:for-each>
				</fromRelationship>
			</xsl:if>
			<xsl:if test="toRelationshipList">
				<toRelationship>
					<xsl:for-each select="toRelationshipList/relationship">
						<xsl:call-template name="relation"/>
					</xsl:for-each>
				</toRelationship>
			</xsl:if>
		</xsl:element>
	</xsl:template>
	<xsl:template name="attribute">
		<xsl:element name="{translate(name,' ','')}">
			<xsl:value-of select="*[2]"/>
		</xsl:element>
	</xsl:template>
	<xsl:template name="state">
		<xsl:element name="state">
			<xsl:element name="name">
				<xsl:value-of select="name"/>
			</xsl:element>
			<xsl:element name="current">
				<xsl:value-of select="stateStatus"/>
			</xsl:element>
			<xsl:element name="actual">
				<xsl:value-of select="actualInfo/datetime"/>
			</xsl:element>
			<xsl:element name="start">
				<xsl:value-of select="startDate/datetime"/>
			</xsl:element>
			<xsl:element name="end">
				<xsl:value-of select="endDate/datetime"/>
			</xsl:element>
			<xsl:element name="duration">
				<xsl:value-of select="stateDuration"/>
			</xsl:element>
		</xsl:element>
	</xsl:template>

	<xsl:template name="relation">
		<xsl:element name="{translate(relationshipDefRef,' ','')}">
			<xsl:element name="relationshipDefRef">
				<xsl:value-of select="relationshipDefRef"/>
			</xsl:element>
			<xsl:element name="objectType">
				<xsl:value-of select="relatedObject/businessObjectRef/objectType"/>
			</xsl:element>
			<xsl:element name="objectName">
				<xsl:value-of select="relatedObject/businessObjectRef/objectName"/>
			</xsl:element>
			<xsl:element name="objectRevision">
				<xsl:value-of select="relatedObject/businessObjectRef/objectRevision"/>
			</xsl:element>
			<xsl:element name="vaultRef">
				<xsl:value-of select="relatedObject/businessObjectRef/vaultRef"/>
			</xsl:element>
			<xsl:for-each select="attributeList/attribute">
				<xsl:call-template name="attribute"/>
			</xsl:for-each>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>
output
Code:
<?xml version='1.0' ?>
V6R2009x.HF29(13.0.0.0)2011-02-17T02:41:20ZexporteMatriXML version V6R2008-1.0<ADDComplaint><Type>ADD Complaint</Type><Name>Ticket Eight 00001</Name>

Last edited by chilly; February 22nd, 2011 at 06:46 PM..
 
Old February 23rd, 2011, 04:08 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Just add another template to handle any elements you don't want to output:

Code:
<xsl:template match="creationProperties"><!-- do nothing --></xsl:template>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old February 23rd, 2011, 10:29 AM
Authorized User
 
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Works pretty good, thanks for the tip
 
Old February 23rd, 2011, 02:53 PM
Authorized User
 
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

in the source data, i am getting some special characters where the field values are converted into xml tags into output.

I am already doing the translation to remove the space

Is there a generic template i can use to pass the values which will remove all the special characters where the name is valid element in xml output

Source
<name>region/state</name>
<string>text goes here</string>

Output
<regionstate>text goes here</regionstate>
 
Old February 24th, 2011, 06:37 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You can use a little trick with translate to do this.

If you pass the text through translate twice, the first time removing all the character you want to keep, then passing this in as the second parameter will remove all the remaining character. See this example where we keep all letters and the underscore character:

Code:
<xsl:variable name="text" select="'region/state'"/>
		<xsl:value-of select="translate($text, translate($text,'ABCDEFGHIJKLMENOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_',''),'')"/>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old February 24th, 2011, 10:14 AM
Authorized User
 
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If i like to keep the numbers, the following might work as well?

<xsl:element name="{translate(name, translate(name,'ABCDEFGHIJKLMENOPQRSTUVWXYZabcdefg hijklmnopqrstuvwxyz0123456789_',''),'')}">
 
Old February 24th, 2011, 10:31 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Yes, precisely. Whatever you include in the inner translate is what is not stripped out from the outer translate.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Swapping values between Element Name and documentation chilly XSLT 4 February 8th, 2011 01:09 PM
Insert multiple elements based on values of others fixit XSLT 14 September 25th, 2009 05:36 AM
convert list of ';' separated values --> elements Condor76 XSLT 1 June 11th, 2007 02:56 PM
HTML table with missing values (elements) go4java XSLT 6 July 10th, 2006 03:31 AM
xml element values vakorde XSLT 3 May 2nd, 2006 04:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.