XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Karen FoxSubject: Problem Setting Variable
Author: Karen Fox
Date: 15 Apr 2008 04:38 PM
I'm trying to create a variable using the output of an xsl:choose. However, I keep getting back an empty variable. I need to validate whether a certain field in the XML document has a value from one of the two imported documents. Could someone please guide me in the right direction? I need to be able to check this variable afterward to see if it has content or not. Thank you.

Karen Fox
kfox@mitre.org

XSL:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ucore="urn:ucore:2.0">

<xsl:variable name="eventsDoc" select="document('EventTypeList.xml')"/>
<xsl:variable name="entityDoc" select="document('EntityTypeList.xml')"/>

<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="ucore:what">
<xsl:variable name="myType" select="@value"/>
<xsl:variable name="found">
<xsl:choose>
<xsl:when test="contains($myType,'Entity')">
<xsl:for-each select="$entityDoc/EntityList/entity">
<xsl:if test="$myType=@id">
<xsl:element name="ucore:what">
<xsl:attribute name="value">
<xsl:value-of select="$myType"/>
</xsl:attribute>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:when test="contains($myType,'Event')">
<xsl:for-each select="$eventsDoc/EventList/event">
<xsl:if test="$myType=@id">
<xsl:element name="ucore:what">
<xsl:attribute name="value">
<xsl:value-of select="$myType"/>
</xsl:attribute>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$found"/>
</xsl:template>
</xsl:stylesheet>

Portion of XML document being transformed:

<?xml version="1.0" encoding="UTF-8"?>
<ulexpd:doPublish
xmlns:new="http://somewhere.gov/new-community"
xmlns:ulexpd="ulex:message:pd:1.0"
xmlns:ulex="ulex:message:structure:1.0"
xmlns:ulexcodes="ulex:message:codes:1.0"
xmlns:ucore="urn:ucore:2.0"
xmlns:ucore-ulex="urn:ucore:2.0:ulex-integration"
xmlns:icism="urn:us:gov:ic:ism:v2"
xmlns:ddms="http://metadata.dod.mil/mdr/ns/DDMS/1.4/"
xmlns:gml="http://www.opengis.net/gml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
ulex:message:pd:1.0 ../import/ULEX1.0beta/xsd/ulex/ulex-publish-discover/1.0/ulex-publish-discover.xsd
ulex:message:codes:1.0 ../import/ULEX1.0beta/xsd/ulex/ulex-codes/1.0/ulex-codes.xsd
ulex:message:structure:1.0 ../import/ULEX1.0beta/xsd/ulex/ulex/1.0/ulex.xsd
urn:ucore:2.0 ../ucore.xsd
http://metadata.dod.mil/mdr/ns/DDMS/1.4/ ../import/DDMSv1.4.1/ns/DDMS/1.4.1/DDMS-v1_4_1.xsd
urn:ucore:2.0:ulex-integration ../ulex-integration/ulex-integration.xsd">
<ulex:PublishMessageContainer>
<!--======================= Message =======================-->
<ulex:PublishMessage>
<ulex:PDMessageMetadata>
<ulex:ULEXFramework>
</ulex:ULEXFramework>
<ulex:ULEXImplementation>
<ulex:ULEXImplementationVersion></ulex:ULEXImplementationVersion>
<ulex:ULEXImplementationName></ulex:ULEXImplementationName>
</ulex:ULEXImplementation>
<ulex:MessageDateTime>2001-12-17T09:30:47.0Z</ulex:MessageDateTime>
<ulex:MessageSequenceNumber>1</ulex:MessageSequenceNumber>
</ulex:PDMessageMetadata>
<!--======================= Data Submitter Metadata =======================-->
<ulex:DataSubmitterMetadata>
<ucore-ulex:SystemIdentifier>System ABC</ucore-ulex:SystemIdentifier>
<ucore-ulex:SystemContact>
<ddms:Organization>
<ddms:name>Colorado Springs Fire Department</ddms:name>
<ddms:phone>719-555-5555</ddms:phone>
<ddms:email>abc@xyz.gov</ddms:email>
</ddms:Organization>
</ucore-ulex:SystemContact>
</ulex:DataSubmitterMetadata>
<!--==================== Package ====================-->
<ulex:DataItemPackage>
<ulex:PackageMetadata>
<ulex:DataItemID>23456789</ulex:DataItemID>
<ulex:DataItemCompleteIndicator>false</ulex:DataItemCompleteIndicator>
<ulex:DataItemDate>2008-04-11</ulex:DataItemDate>
<ulex:DataItemReferenceID>23456789</ulex:DataItemReferenceID>
<ucore-ulex:DataItemStatus>Updated Vehicle Position Report</ucore-ulex:DataItemStatus>
<!--======================= Data Owner Metadata =======================-->
<ulex:DataOwnerMetadata>
<ucore-ulex:DataOwnerIdentifier>
<ddms:Organization>
<ddms:name>Colorado Springs Fire Department</ddms:name>
</ddms:Organization>
</ucore-ulex:DataOwnerIdentifier>
<ucore-ulex:DataOwnerContact>
<ddms:Organization>
<ddms:name>Colorado Springs Fire Department</ddms:name>
<ddms:phone>719-555-5555</ddms:phone>
<ddms:email>abc@xyz.gov</ddms:email>
</ddms:Organization>
</ucore-ulex:DataOwnerContact>
</ulex:DataOwnerMetadata>
<ucore-ulex:DisseminationCriteria icism:classification="U"/>
</ulex:PackageMetadata>
<!--======================= Digest =======================-->
<ucore-ulex:digest>
<ucore-ulex:metadata icism:classification="U" icism:ownerProducer="USA"/>

<!--Arrival Event-->
<ucore:Event id="Arrival">
<ucore:descriptor>"Arrival in Port"</ucore:descriptor>
<ucore:what value="Event.Planned.Today" />
<ucore:time>
<ucore:instant><ucore:dateTime>2004-04-01T06:00:00</ucore:dateTime></ucore:instant>
</ucore:time>
</ucore:Event>

<!--Vessel-->
<ucore:Entity id="ARR3232">
<ucore:descriptor>Atlantic Light</ucore:descriptor>
<ucore:what value="Entity.PhysicalObject.Conveyance.Vehicle"/>
</ucore:Entity>
</ulex:DataItemPackage>
</ulex:PublishMessage>
</ulex:PublishMessageContainer>
</ulexpd:doPublish>

Karen Fox
kfox@mitre.org

Postnext
Alberto MassariSubject: Problem Setting Variable
Author: Alberto Massari
Date: 16 Apr 2008 03:18 AM
Hi Karen,
the variable is created correctly; the bug is in the use of xsl:value-of to print it, as the text value of <ucore:what> element stored inside the variable is an empty string. You should use <xsl:copy-of select="$found"/> instead.

Hope this helps,
Alberto

Posttop
Karen FoxSubject: Problem Setting Variable
Author: Karen Fox
Date: 16 Apr 2008 10:09 AM
Thanks so much, Alberto. That did it. I hate to think of how long I spent wrestling with that. You're a lifesaver!

Karen Fox
kfox@mitre.org

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.