473,499 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

easy(?) question about cross referencing in XSLT

Hi

I have what I think is a easy question about how to pull cross
reference data
when I transform my XML file. I can't seem to find a good example of
how to do
this on the web, though.

Here is the XML file I am supposed to process:

<property address="1235 Wildwood">
<ownerRef ownerKey="100"/>
<ownerRef ownerKey="130"/>
</property>

<owner ownerId="100" name="J. Smith"/>
<owner ownerId="130" name="E. Rock"/>
When I process the property element, I want to look up the owner names
and print
them also. I'm guessing something with xsl:key maybe??

thanks,
Jeff

Jan 20 '06 #1
3 1208
Hi,

When I process the property element, I want to look up the owner names
and print
them also. I'm guessing something with xsl:key maybe??


Absolutely ;) Keys are the answer.

Soren
Jan 21 '06 #2
Hi Jeff,

Here it is a sample:

<test>
<property address="1235 Wildwood">
<ownerRef ownerKey="100"/>
<ownerRef ownerKey="130"/>
</property>
<owner ownerId="100" name="J. Smith"/>
<owner ownerId="130" name="E. Rock"/>
</test>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:key name="ownerById" match="owner" use="@ownerId"/>
<xsl:template match="property">
<xsl:for-each select="ownerRef">
<xsl:value-of select="key('ownerById', @ownerKey)/@name"/>
<xsl:if test="position()!=last()">
<xsl:text>, </xsl:text></xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

gives

J. Smith, E. Rock

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Jan 23 '06 #3

George Bina wrote:
Hi Jeff,

Here it is a sample:

<test>
<property address="1235 Wildwood">
<ownerRef ownerKey="100"/>
<ownerRef ownerKey="130"/>
</property>
<owner ownerId="100" name="J. Smith"/>
<owner ownerId="130" name="E. Rock"/>
</test>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:key name="ownerById" match="owner" use="@ownerId"/>
<xsl:template match="property">
<xsl:for-each select="ownerRef">
<xsl:value-of select="key('ownerById', @ownerKey)/@name"/>
<xsl:if test="position()!=last()">
<xsl:text>, </xsl:text></xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

gives

J. Smith, E. Rock

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


Thanks, George! That example was very helpful!

--Jeff

Jan 23 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2544
by: Simon Harvey | last post by:
Hi everyone, I am fairly new to learning about xsl and xml, but one thing I have noticed is that anyone offering a tutorial or lesson on it seems to think that its the most incredible invention...
3
4580
by: Luther Miller | last post by:
I am using an XSLT file to convert data in a DataSet to XMLSS format for opening in Excel. Excel doesn't like the way Dates in the DataSet are being ouput. It appears that a timezone offset is...
5
1067
by: Bruce D | last post by:
Being new to .NET, prompts this question: Why is it that when I open one of my .aspx pages (it only happens with one of them), it always gets marked with the * to save changes...right after I open...
1
1261
by: google | last post by:
I have one xml file, content.xml, and three views, 1.xsl, 2.xsl, 3.xsl. I would like to be able to link from any of the views to any of the other views. I can do this if I use, say saxon to...
0
1072
by: duke442games | last post by:
OK, I need to select RealName from tblUser where the userid on tblUser matches the approvedby on tblCutList This is incredibly easy, but it keeps erroring out. Please help!!!
4
1487
by: Lord0 | last post by:
Hi there, Is the following possible with XSLT? Given the following example XML docs: <!-- doc 1--> <user> <username>myUsername</username> <password></password> <phone>12345</phone>
1
1222
by: Toxician | last post by:
why can i use javascrtip to output the file below into html and also able to use xslt to do the same thing ??? xml.xml <root> <node>This is a node </node> <root> ************************...
1
2565
by: NevilleDNZ | last post by:
Hi, Apologies first as I am not a unicode expert.... indeed I the details probably totally elude me. Not withstanding: how can I convert a binary string containing UTF-8 binary into a python...
2
22747
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values...
0
7130
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3098
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.