IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

Mapping a list simple type to repeating element Options · View
JamesB
Posted: Friday, May 18, 2007 9:53:31 AM
Rank: Newbie

Joined: 5/18/2007
Posts: 3
Location: UK
I'm trying to generate an XSLT in Mapforce which maps a whitespace separated list of tokens (successfully modelled in an w3c XSD source schema) to a XSD schema which models the information using an unbounded element (with a complex type).
How can I do this without using string-before and string-after to tokenise only a limited length list?

Details of source schemas simple type
Code:
    
<xs:simpleType name="offsetList">
  <xs:restriction base="abxls:offsetListItem"/>
</xs:simpleType>
   
<xs:simpleType name="offsetListItem">
  <xs:annotation>
    <xs:documentation>Item for offsetList</xs:documentation>
  </xs:annotation>
  <xs:list itemType="abxls:millimetresCanonical"/>
</xs:simpleType>


Details of destination schemas complex type
Code:

<xs:element name="SF-TO">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="TrackOffset" maxOccurs="unbounded">
                <xs:simpleType>
                    <xs:restriction base="sp17:millimetres">
                        <xs:minExclusive value="0"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>
JamesB
Posted: Friday, May 25, 2007 2:16:53 PM
Rank: Newbie

Joined: 5/18/2007
Posts: 3
Location: UK
It seems this just isn't possible in MapForce. I say this because I just can't find a way to generate unbounded outputs based on a single input i.e. one-many.

I can easily adapt a generated xslt to do exactly what I want using a recursive template but as my template outputs structured text I can't import it to MapForce without MapForce generating code which selects the templates "output" into a single instance of my target element.

i.e.
Code:
<OffsetList>10mm 20mm 1mm 455mm</OffsetList>

becomes
Code:
<SF-TO>
<TrackOffset>10201455</TrackOffset>
</SFTO>

instead of
Code:
<SF-TO>
<TrackOffset>10</TrackOffset>
<TrackOffset>20</TrackOffset>
<TrackOffset>1</TrackOffset>
<TrackOffset>455</TrackOffset>
</SFTO>


I can ammend the xslt myself but it isn't exactly practical having to make numerous fixes whenever I regenerate my mapping. I might as well handcode my xslt!
ckapop
Posted: Sunday, October 7, 2007 2:15:40 PM
Rank: Newbie

Joined: 1/23/2007
Posts: 1
Has there been an official response to this? I have the same issue and it seems like this should be something that MapForce handles. The online docs dont mention anything about splitting up value lists using functions of anykind.

The xsd states that this value is a list of n number of values. Why not talk about how to split these into new nodes or why it cant be done.

Thanks.

JamesB wrote:
It seems this just isn't possible in MapForce. I say this because I just can't find a way to generate unbounded outputs based on a single input i.e. one-many.

I can easily adapt a generated xslt to do exactly what I want using a recursive template but as my template outputs structured text I can't import it to MapForce without MapForce generating code which selects the templates "output" into a single instance of my target element.

i.e.
Code:
<OffsetList>10mm 20mm 1mm 455mm</OffsetList>

becomes
Code:
<SF-TO>
<TrackOffset>10201455</TrackOffset>
</SFTO>

instead of
Code:
<SF-TO>
<TrackOffset>10</TrackOffset>
<TrackOffset>20</TrackOffset>
<TrackOffset>1</TrackOffset>
<TrackOffset>455</TrackOffset>
</SFTO>


I can ammend the xslt myself but it isn't exactly practical having to make numerous fixes whenever I regenerate my mapping. I might as well handcode my xslt!
maverik11
Posted: Wednesday, October 17, 2007 12:18:49 PM
Rank: Advanced Member

Joined: 10/10/2005
Posts: 35
Location: AT
If the number of items in the list is known it is possible to map them to separate elements, by using string functions to split the list contents and map the results to duplicated versions of the target node (right click the target node and select "Duplicate Input").

Unfortunately, it is currently not possible to to map this in case of an unknown number of list elements. However, I added your comments to our Feature Request database. The matter has the tracking number and title:

"22601 - ability to treat list members as repeating elements"



Christian B

... Support Engineer
... Altova GmbH
evoboxaccount
Posted: Monday, May 18, 2009 1:49:30 PM
Rank: Newbie

Joined: 5/18/2009
Posts: 1
Location: france
Is there any newer answer on this topic?
problem we have to solve is:
source file is xml but some elements contain:
...
<list>a1|a2|a3|a4</list>
...
number of data separated with | is unknown
which should result in:
...
<elt_master>
<elt_child>a1</elt_child>
<elt_child>a2</elt_child>
<elt_child>a3</elt_child>
<elt_child>a4</elt_child>
</elt_master>

thanks for your answer.
regards,

ps: this is feasible with xslt by recursive cal of function like:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template name="output-tokens">
<xsl:param name="list" />
<xsl:param name="delimiter" />
<xsl:param name="str_xml"/>
<xsl:variable name="newlist">
<xsl:choose>
<xsl:when test="contains($list, $delimiter)"><xsl:value-of select="normalize-space($list)" /></xsl:when>
<xsl:otherwise><xsl:value-of select="concat(normalize-space($list), $delimiter)"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="first" select="substring-before($newlist, $delimiter)" />
<xsl:variable name="remaining" select="substring-after($newlist, $delimiter)" />
<elt_child><xsl:value-of select="$first" /></elt_child>

<xsl:if test="$remaining">
<xsl:call-template name="output-tokens">
<xsl:with-param name="list" select="$remaining" />
<xsl:with-param name="delimiter"><xsl:value-of select="$delimiter"/></xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>


maverik11 wrote:
If the number of items in the list is known it is possible to map them to separate elements, by using string functions to split the list contents and map the results to duplicated versions of the target node (right click the target node and select "Duplicate Input").

Unfortunately, it is currently not possible to to map this in case of an unknown number of list elements. However, I added your comments to our Feature Request database. The matter has the tracking number and title:

"22601 - ability to treat list members as repeating elements"



Christian B

... Support Engineer
... Altova GmbH
lisadp
Posted: Tuesday, June 16, 2009 3:17:06 AM
Rank: Newbie

Joined: 6/16/2009
Posts: 4
Location: Adelaide
We also noted that this functionality wasn't available (actually we thought we just couldn't figure out how to do it). To me it seems like it would be a very common need. Also, as pointed out, it's so easy to do manually in XSLT.

Good to hear this is in the list of feature requests.
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.