Subject:Link multiple files Author:Yvonne de Vries Date:29 Sep 2005 07:10 AM
Hello,
I hope anybody can help me.
I’m new in Stylus Studio and I have a difficult problem. At least for me.
I have an XML sheet exported from an Account program.
I have a node GLAccount and a node Costcenter. The number in the node GLAccount has to be changed, but in what that depends of two other tables.
Suppose the GL Account = 4000.
I look in table1 and find that GLAccount 4000 has a code of 220. In that case I know I have to do something, otherwise I can go to the next “record”.
If it’s code 220 I have to look in the main XML sheet to the costcenter. Suppose this is costcenter 15, than I have to look in table2 for the code belonging to costcenter 15. This code I concatenate to the GLAccount (4000).
I have linked the exported XML sheet to an Schema. Because in that case I got an xsl file and I suppose that I have to use the When clause in xsl in order to handle this problem. But maybe I´m wrong and I can change the values in an XML file.
Subject:Link multiple files Author:(Deleted User) Date:04 Oct 2005 11:52 AM
Can you please provide us with additional info ?
1) Which file do I have to use to find GLAccount value? The only file where I was able to find GLAccount node is FinEntries.doc, but it does not seem to be the right one.
Do I have to look in GrootboekVerdichtingscode.xml to get the values ?
2) Assuming the GLAccount value will be obtained from GrootboekVerdichtingscode.xml <Grtbk.>4000</Grtbk.>, and assuming the code can be obtained from the same file from <Verd.>220</Verd.> element, how will we link 4000 value with the cost center ? If we have to look into the FinEntries.doc to find costcenter
a) how will we select proper GLAccount ?
b)
<GLAccount code=" 1010" type="B" side="D">
<Description>CASH FOREIGN CURRENCY</Description>
</GLAccount>
is code attribute contains conscenter ?
3) Do we have to look for the string to concatinate in Verdicode_USGAAP_NL.xml ? if so,
<Kostenplaats>9</Kostenplaats> - is it a costcenter code ?
<USGAAPcode>5</USGAAPcode> - is it a string to concatinate ?
Subject:Link multiple files Author:Yvonne de Vries Date:04 Oct 2005 03:01 PM
FinEntry.doc is actually a very big xml file. This file is exported from our accounting program. I just copied / pasted a part of the whole file into a word document.
In FinEntry.doc there is an Element named GLAccount with an attribute code.
If this code is a value in the table GrootboekVerdichtingscode.xml then I have to look in the
FinEntry.xml to the Costcenter element – attribute: code (in the same FinEntryLine ofcourse). If I found the Costcenter, I must look in the Verdicode_USGAAP_NL.xml to the USGAAPCode belonging to that Costcenter. This code I must concatenate with the GLAccount code and write it back to the GLAccount code.
I hope this explanation is clear enough. I tried a lot in Stylus Studio, but until now without success.
Thanks for your help. It’s very much appreciated.
Subject:Link multiple files Author:(Deleted User) Date:04 Oct 2005 05:55 PM
Take a look at the following XQuery. I hope it will do what you want.
declare function local:ConcatAccount($account, $match as xs:integer) as xs:string
{
(:We will perform transformation only in case Verd. = 220 :)
if($match eq 220) then
(: Let's try to find a code attribute for the GLAccount element in the main xml :)
(: The code attribute value must match with the value extracted from "Grtbk." :)
(: This predicate does comparation : '[number(@code) eq number($account)]' :)
let $code := doc("Main.xml")/FinEntries/FinEntry/FinEntryLine/GLAccount[number(@code) eq number($account)]/@code
return
(: check if we've found matching code :)
if(count($code) eq 1) then
(: let's get costcenter from the same record :)
let $costcenter := string($code/../../Costcenter/@code)
return
(: check that we've found conscenter :)
if(count($costcenter) eq 1) then
(: let's search for addition to the Grtbk. using conscenter in our 3-d file :)
(: we have to find a row with 'Kostenplaats' equal to costcenter we've extracted :)
let $addon := doc("Verdicode_USGAAP_NL.xml")/document/row/Kostenplaats[number(.) eq number($costcenter)]
return
(: if addition found concatinate it with original value of "Grtbk." :)
if(count($addon) eq 1) then concat(concat($account, "-"), $addon/../USGAAPcode)
else string($account)
else string($account)
else string($account)
else string($account)
};
<document>
{
for $x in /document/row
return <row><Grtbk.>{ local:ConcatAccount($x/Grtbk., $x/Verd.) }</Grtbk.>{ $x/Verd. }</row>
}
</document>
Subject:Link multiple files Author:Yvonne de Vries Date:09 Oct 2005 03:31 AM
Thank you for your code. But where must I do the function call? I have tried it in
GLAccount under
<xsl:attribute name="code">
<xsl:value-of select="GLAccount/@code"/>
and I wrote the function after
</xsl:template>
Must I declare
<xsl:script language="JavaScript">?
If there is additional information I can read, please let me know. It's not well documented in the User guide. At least I can't find it.
Subject:Link multiple files Author:Yvonne de Vries Date:10 Oct 2005 04:55 PM
Thank you. It works perfect. But, I have to make the call from the main.xml in stead of from the GrootboekVerdichtingscode.xml. Code is an attribute. Can I use this sentence in the calling code:
<FinEntries>
{
for $x in /FinEntries/FinEntry/FinEntryLine/GLAccount/code
return <FinEntries><FinEntry><FinEntryLine><GLAccount><code>{ local:ConcatAccount($x/code) }</GLAccount><</FinEntryLine></FinEntry>
}
</FinEntries>
I have to change the value of the attribute code in the main.xml and not the value of the element code value in GrootboekVerdichtingscode.xml. Does that change anything in the code?
Subject:Link multiple files Author:(Deleted User) Date:11 Oct 2005 03:22 PM
Yes, the code will change. You'll have to walk on your "Main.xml" copying everything except account to the output. local:ConcatAccount
function will change. It will get just an account number as a parameter
and you will have to extract "match" from GrootboekVerdichtingscode.xml.
Of cause you will have to search for the account and code in GrootboekVerdichtingscode.xml instead of main.xml.
Subject:Link multiple files Author:Yvonne de Vries Date:11 Oct 2005 06:10 PM
Thank you for your answer.
I wrote this code (the function is empty for the moment), but I keep having error messages. Can you please tell me what is wrong. I use the mapper, but the moment I want to call the function, I get error messages.
declare function local:ConcatCode($code as xs:integer) as xs:string
{
return
};
<FinEntries>
<FinEntry>
<FinEntryLine>
<GLAccount>
}
for $x in /FinEntries/FinEntry/FinEntryLine/GLAccount/@code
return <FinEntry><FinEntryLine><GLAccount>{local:ConcatCode($x/@Code)}
}
</GLAccount>
</FinEntryLine>
</FinEntry>
</FinEntries>
Thank you very much. Can I find somewhere documentation about this, because I can not find it in the Stylus Studio user Guide.
Subject:Link multiple files Author:(Deleted User) Date:12 Oct 2005 08:00 AM
Function can not have just return - this is syntax error. Here is the correct syntax:
declare function local:ConcatCode($code as xs:integer) as xs:string {
let $x:= ""
return $x
};
<FinEntries>
{
for $x in /FinEntries/FinEntry/FinEntryLine/GLAccount/@code
return <FinEntry><FinEntryLine><GLAccount>{local:ConcatCode($x/@Code)}</GLAccount></FinEntryLine></FinEntry>
Subject:Link multiple files Author:Yvonne de Vries Date:18 Oct 2005 08:35 AM
Thank you very much about all your help. I have written all the functions I need and it works great. If you want to view my solution, please let me know and I will post them here on the network.