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
Jon GallegosSubject: Looping question
Author: Jon Gallegos
Date: 14 Apr 2008 03:20 PM
I have been using another mapper to map XML but have been asked to learn Stylus Studio and to learn it in aq week. So the first quesiton I have has to do with looping. i have the following input schema

<xs:element name="TestIn">
<xs:complexType>
<xs:sequence>
<xs:element ref="controlNumber"/>
<xs:element ref="internalID"/>
<xs:element ref="UserEmail"/>
<xs:element ref="ns1:department"/>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="ns1:part"/>
<xs:element ref="ns1:effect"/>
</xs:sequence>
</xs:complexType>
</xs:element>


and the output schema


<xs:element name="TestOut">
<xs:element name="form">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="UserData"/>
</xs:sequence>
<xs:attribute name="id" use="required" type="xs:integer"/>
<xs:attribute name="name" use="required"/>
<xs:attribute name="subClass" use="required" type="xs:NCName"/>
<xs:attribute name="subType" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="UserData">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="UserValue"/>
</xs:sequence>
<xs:attribute name="id" use="required" type="xs:integer"/>
<xs:attribute name="type" use="required" type="xs:NCName"/>
</xs:complexType>
</xs:element>
<xs:element name="UserValue">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="UserList"/>
</xs:sequence>
<xs:attribute name="title" use="required"/>
<xs:attribute name="value" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="UserList">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="Item"/>
</xs:sequence>
<xs:attribute name="id" use="required" type="xs:integer"/>
<xs:attribute name="type" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="Item">
<xs:complexType>
<xs:attribute name="value" use="required"/>
</xs:complexType>
</xs:element>

The "Control Number", "internalID", "UserEmail", and "department" will go into UserValue "Value" with a hardcoded title for each occurance. Part is to into item. Can someone please explain how I get the looping started and how I can loop into memory and pull it back out?

input data


The input data is to look something like this
<TestIn>
<controlNumber>100006</controlNumber>
<internalID>ID1006</internalID>
<userEmail>name@email.com</userEmail>
<department>DeptNbr16</department>
<part>
<partnbr>12345</partnbr>
<partnbr>12346</partnbr>
<partnbr>12347</partnbr>
</part>
<effect>Effecto</effect>
</TestIn>

and the output data is to be formated like this


<form id="1" name="" subType="TestOut" subClass="TestOutSubclass">
<UserData id="2" type="FormAttributes">
<UserValue title="ControlNumber" value="100006"></UserValue>
</UserData>
</form>
<form id="3" name="" subType="TestOut" subClass="TestOutSubclass">
<UserData id="4" type="FormAttributes">
<UserValue title="InternalID" value="ID1006"></UserValue>
</UserData>
</form>
<form id="5" name="" subType="TestOut" subClass="TestOutSubclass">
<UserData id="6" type="FormAttributes">
<UserValue title="UserEmail" value="name@email.com"></UserValue>
</UserData>
</form>
<form id="7" name="" subType="TestOut" subClass="TestOutSubclass">
<UserData id="8" type="FormAttributes">
<UserValue title="Department" value="16"></UserValue>
</UserData>
</form>
<form id="9" name="" subType="TestOut" subClass="TestOutSubclass">
<UserData id="10" type="FormAttributes">
<UserValue title="PartNumber">
<UserList id="#10" type="">
<Item value="US">12345</Item>
</UserList>
</UserValue>
</UserData>
</form>
<form id="11" name="" subType="TestOut" subClass="TestOutSubclass">
<UserData id="12" type="FormAttributes">
<UserValue title="PartNumber">
<UserList id="#12" type="">
<Item value="US">12346</Item>
</UserList>
</UserValue>
</UserData>
</form>
<form id="13" name="" subType="TestOut" subClass="TestOutSubclass">
<UserData id="14" type="FormAttributes">
<UserValue title="PartNumber">
<UserList id="#14" type="">
<Item value="US">12347</Item>
</UserList>
</UserValue>
</UserData>
</form>
<form id="7" name="" subType="TestOut" subClass="TestOutSubclass">
<UserData id="8" type="FormAttributes">
<UserValue title="effect" value="Effecto"></UserValue>
</UserData>
</form>

Postnext
Alberto MassariSubject: Looping question
Author: Alberto Massari
Date: 15 Apr 2008 05:38 AM
Hi Jon,
I don't have the full schema, so I will try to guess some of the parts.

- keeping the right mouse button pressed, drag a link from TestIn to TestOut, and pick "Create Repeatable Link"
- right click on the subType attribute in the output tree, choose "Set Text Value" and enter 'TestOut'
- enter the fixed values also for subClass, name, and type (for UserData)
- right click on the middle pane, pick XSLT Functions, then local-name()
- drag a link from controlNumber to the input port of local-name, and a link from the output port to the 'title' attribute of UserValue (as an alternative, you could also use the Set Text Value command also here)
- drag a link from controlNumber to the 'value' attribute of UserValue

- right click on the 'form' element in the target schema tree and pick "Duplicate node", and repeat the same operations using the "internalID" source element.

- repeat the same process for the remaining input elements.

In order to compute the 'id' attributes, I think you could specify for each attribute a Set Text Value option of "{count(preceding-sibling::*)*16+x}" where "x" is 1 for the 'id' attribute of the first 'form' element, 2 for the 'id' of UserData, 3 for the 'id' attribute of the second 'form' (the first one you duplicated) and so on.

Hope this helps,
Alberto

Postnext
Jon GallegosSubject: Looping question
Author: Jon Gallegos
Date: 15 Apr 2008 08:51 AM
Alberto

Thank you. I will give this a try


//jvg

Postnext
Jon GallegosSubject: Looping question
Author: Jon Gallegos
Date: 15 Apr 2008 10:44 AM
Alberto

How do I control a loop?

//jvg

Postnext
Alberto MassariSubject: Looping question
Author: Alberto Massari
Date: 15 Apr 2008 01:02 PM
Hi Jon,
what do you mean by "control a loop"? Can you make an example?

Alberto

Postnext
Jon GallegosSubject: Looping question
Author: Jon Gallegos
Date: 15 Apr 2008 01:22 PM
First of all, I am sorry I can not send you a schema. All is proprietary.

Having said that, here is an example;

<Header>
<PONumber>PO1</PONumber>
<Detail>
<ItemNumber>111</ItemNumber>
<ItemNumber>222</ItemNumber>
<ItemNumber>333</ItemNumber>
</Detail>
<PONumber>PO2</PONumber>
<Detail>
<ItemNumber>111</ItemNumber>
<ItemNumber>222</ItemNumber>
</Detail>
</Header>

When I map this order, I will need to control the loops so my output file has three items in the first purchase order and two in the second. If I mapped this in Stylus Studio using "Create Repeatable Link", the first order will have five items and the second will have none.

How do I get three items in the first purchase order and two in the second?


//jvg

Postnext
Alberto MassariSubject: Looping question
Author: Alberto Massari
Date: 16 Apr 2008 03:06 AM
Hi Jon,
this fragment looks very different from the original question... it looks more a whole different problem. As you don't display the XSLT code, and don't say how you created the links, I can only suggest you to double check that the repeating link starts from PONumber instead of ItemNumber.

Alberto

Postnext
Jon GallegosSubject: Looping question
Author: Jon Gallegos
Date: 16 Apr 2008 11:45 AM
Ok

Here are the two xsd files. I can send them to you because they do not have any information on them.

On the source side the root is eCrfs. The child of eCrfs is eCRF. there may be multiple eCrf records.

On the target side the root is PLMXML. There is four children to PLMXML; Header, Product, Product Revision, and Form.

For every source eCrf there is one Header, Product, Product Revision and Form.

Right now I have the looping link on Source eCRF and Target Form. So for Every eCRF record I get a Form record. This does do becuase I only have one Header, one Product, and one Product Revision.

What do i need to do to make this loop correctly>


DocumentPDHXML.xsd
This is the Source XSD

UnknownPLMXML.xsd
Target xsd

Postnext
Alberto MassariSubject: Looping question
Author: Alberto Massari
Date: 17 Apr 2008 03:57 PM
Hi Jon,
if you want to create all the four Header, Product, ProductRevision and form for each eCrf present in the source file, you should right click on the canvas, pick the XSLT Instructions -> for-each block, then drag a link from eCrf to the input port, then drag four links from the output port to each of the target elements.
Then continue with the mapping of the children of the eCrf, as explained in my first post.

Hope this helps,
Alberto

Postnext
Jon GallegosSubject: Looping question
Author: Jon Gallegos
Date: 17 Apr 2008 04:58 PM
Cool

That did the trick

thanks

//jvg

Postnext
Jon GallegosSubject: Looping question
Author: Jon Gallegos
Date: 28 Apr 2008 02:56 PM
I have a file that has three records. Currently there is a one to one relationship between these three records and the loops multipe times. In the Header record the "traverseRootRefs" contains a number that referese to the ProductRevision record.

Here is an example of what it currently looks like;
<Header id="1" traverseRootRefs="#2" transferContext="CRF Form Import" />
<Product id="3" subType="Official Part" name="string" productid="string">
<Description>string</Description>
</Product>
<ProductRevision id="2" name="" masterRef="#3" revision="A">
<AssociatedForm id="4" role="IMAN_specification"/>
</ProductRevision>

<Header id="5" traverseRootRefs="#6" transferContext="CRF Form Import" />
<Product Id="7" subType="Official Part" name="string" productid="string">
<Description>string</Description>
</Product>
<ProductRevision id="6" name="" masterRef="#7" revision="A">
<AssociatedForm id="8" role="IMAN_specification"/>
</ProductRevision>

<Header id="9" traverseRootRefs="#10" transferContext="CRF Form Import" />
<Product Id="11" subType="Official Part" name="string" productid="string">
<Description>string</Description>
</Product>
<ProductRevision id="10" name="" masterRef="#11" revision="A">
<AssociatedForm id="12" role="IMAN_specification"/>
</ProductRevision>


However, I have been told that this is not correct. The Header record has a one to many relationship with Product and Product Revision. Product and Product Revision maintain thier one to one relationship. The traverseRootRefs in the Header record referese to each Product Revision id. This is what it is supposed to look like;

<Header id="1" traverseRootRefs="#2#6#10" transferContext="CRF Form Import" />
<Product id="3" subType="Official Part" name="string" productid="string">
<Description>string</Description>
</Product>
<ProductRevision id="2" name="" masterRef="#3" revision="A">
<AssociatedForm id="4" role="IMAN_specification"/>
</ProductRevision>

<Product Id="7" subType="Official Part" name="string" productid="string">
<Description>string</Description>
</Product>
<ProductRevision id="6" name="" masterRef="#7" revision="A">
<AssociatedForm id="8" role="IMAN_specification"/>
</ProductRevision>

<Product Id="11" subType="Official Part" name="string" productid="string">
<Description>string</Description>
</Product>
<ProductRevision id="10" name="" masterRef="#11" revision="A">
<AssociatedForm id="12" role="IMAN_specification"/>
</ProductRevision>

Notice the traverseRootRefs field in the single Header record. How do I do that?

//jvg

Postnext
Alberto MassariSubject: Looping question
Author: Alberto Massari
Date: 29 Apr 2008 06:04 AM
Hi Jon,
you will have to manually add a

<Header transferContext="{/a:eCrf/a:eCrfs/a:reviseNumber}"/>

in the stylesheet, before the xsl:for-each instruction added by Mapper.

Alberto

Postnext
Jon GallegosSubject: Looping question
Author: Jon Gallegos
Date: 29 Apr 2008 09:55 AM
PLease forgive me if I appear a little daft, but I do not understand. I guess I am too new to this product

The transfer Context is to be a static value of "CRF Form Import". The dynamic field is traverseRootRefs. Also
I do not understand reviseNumber. How does that refer to all of the product revision ids ( <ProductRevision id="2" )?

Posttop
Alberto MassariSubject: Looping question
Author: Alberto Massari
Date: 29 Apr 2008 12:12 PM
Hi Jon,
sorry I mistyped the attribute name; it is indeed traverseRootRefs.
I also guessed that reviseNumber could be the source element; you are now saying it comes from a ProductRevision/@id attribute (that I cannot find in the PDHXML.xsd schema), so you should use that XPath.
However, if the '#' sign has to be prefixed to every id, you should probably go through a

<xsl:attribute name="traverseRootDefs">
<xsl:for-each select="/eCrfs/eCrfs/ProductRevision/@id">
<xsl:value-of select="concat('#',.)"/>
</xsl:for-each>
</xsl:attribute>

Alberto

 
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.