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 April 7th, 2005, 06:11 AM
Authorized User
 
Join Date: Mar 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Olaf_l
Default xslt with multiple occurrences in a record

Hi there,

I have a problem creating an xslt-file for the following xml-file (I left out most of the records and fields except for one record :)

Code:
<?xml version="1.0" encoding="UTF-8" ?>
<adlibXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.adlibsoft.com/adlibXML.xsd">
<?xml-stylesheet type="text/xsl" href="test.xsl" ?>
<recordList>
<artiks>
<recordnummer>1</recordnummer>
<title>Nice painting</title>
<dimension_unit>cm</dimension_unit>
<dimension_unit>cm</dimension_unit>
<dimension>hoogte</dimension>
<dimension>breedte</dimension>
<dimension_value>13,5</dimension_value>
<dimension_value>3,5</dimension_value>
<location>zaal 3</location>
</artikels>
</recordList>
I want to import this file into MS Access 2k3. As you can see, info about the dimensions of this painting are double and I want to put the dimensioninformation in a different tabel.

Every first element of a tag belongs to each other, ie "cm, hoogte, 13.5" and "cm, breedte, 3.

An article can have more than 1 dimensions. a Dimension 'depth' is als o an option.

How can i do that. I did some research and i made this XSLT-script.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

<test>
<xsl:for-each select="//recordList/record">
<collect>
  <recordnummer>
    <xsl:value-of select="priref"/>
  </recordnummer>
  <objectnummer>
    <xsl:value-of select="object_number"/>
  </objectnummer>
  <title>
    <xsl:value-of select="title"/>    
  </title>

  <xsl:for-each select="dimension[(position()]">
    <properties>
             <xsl:apply-templates select="recnr"/>
             <xsl:apply-templates select="property"/>
             <xsl:apply-templates select="waarde1"/>
        </properties>    
    </xsl:for-each>

<xsl:template match="recnr">
   <recordnummer><xsl:value-of select="record_number"/></recordnummer>
</xsl:template>

<xsl:template match="property">
   <eigenschap><xsl:value-of select="dimension[(position()]"/></eigenschap>
</xsl:template>

<xsl:template match="waarde">
   <waarde><xsl:value-of select="dimension_value[(position()]"/></waarde>
</xsl:template>

</collect>
</xsl:for-each>
</test>
</xsl:template>
</xsl:stylesheet>
As you can see, there is some more info here about other fields (ignore them please). I made a 'for-each' loop for the dimensionfields , but it doesn't work.

What could be a good solution for my problem?

Tia

 
Old April 7th, 2005, 06:21 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Try

<xsl:for-each select="dimension">
  <xsl:variable name="p" select="position()"/>
  <dimension>
   <name><xsl:value-of select="."/></name>
   <unit><xsl:value-of select="../dimension-unit[$p]"/></unit>
   <value><xsl:value-of select="../dimension-value[$p]"/></value>
  etc.

Note that x[position()] is always wrong, because a numeric predicate N is short for position()=N, so x[position()] means x[position()=position()] which is the same as x.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 7th, 2005, 07:02 AM
Authorized User
 
Join Date: Mar 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Olaf_l
Default

Hi there,

It worked . With some minor adjustments I could transform the xml file and import it into access. My code for the dimensionstuff:

Code:
<xsl:for-each select="dimension">
  <xsl:variable name="p" select="position()"/>
  <eigenschappen>
    <recordnummer><xsl:value-of select="../priref"/></recordnummer>
    <eigenschap><xsl:value-of select="."/></eigenschap>
    <waarde><xsl:value-of select="../dimension_value[$p]"/>  <xsl:value-of select="../dimension_unit[$p]"/></waarde>
  </eigenschappen>
</xsl:for-each>
There is some dutch text in the code, but that is not relevant. It works now and I can use this template for other multiple occurrences.

Thanks for your help. I was working on this for 2 days before i came here






Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT - Don't Repeat if last record mattboy_slim XSLT 2 September 11th, 2007 12:33 PM
Why is multiple record not getting displayed jack123 SQL Server 2000 1 August 8th, 2007 02:31 AM
XSLT Code for Multiple occurrences vijayp2p XSLT 1 May 9th, 2006 11:23 AM
multiple entries from one record techsp Access 2 August 2nd, 2005 10:10 AM
Distinct Column Occurrences jemacc SQL Server 2000 2 October 25th, 2004 04:20 AM





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