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 November 18th, 2010, 06:55 PM
Registered User
 
Join Date: Nov 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Howto test for keys in separate Xml file

Hi WROX XSLT forum,
Im quite new using XSLT templates, but already have a requirement (advanced XSLT for me) im facing multiple files+context roots issue, among others) to no avail yet. In short I need to parse file1.xml and if a element "key" value exists in file2.xml - also an element value, then output the file1 Xml, if not skip.
Ive read a number of web articles discussing combining multiples Xml fiels with XSLT, alas, I havent found a working solution yet. (help!)

------------------------------------

(file1) SamplePeopleSoft.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Rows>
<Row>
...
<SubAccount>D4P8</SubAccount>
...
</Row>
<Row>
...
<SubAccount> D1MW</SubAccount>
...
</Row>
</Rows>

(file2) B1CSHValidPLA.xml

<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="B1CSHValidPLA.xsd" generated="2010-11-04T07:30:00">
<B1CSHValidPLA>
<ID>1</ID>
<ValidPLA>B1CSH0044C</ValidPLA>
</B1CSHValidPLA>
...
</dataroot>

(my .xsl with several attempts...)

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

<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />

<xsl:variable name="b1cshvalidPLADoc" select="document('B1CSHValidPLA.xml')" />

<xsl:key name="validPLAkeys" match="B1CSHValidPLA" use="ValidPLA"/>

<xsl:template match="/">

<xsl:for-each select="document('B1CSHValidPLA.xml')">
<xsl:value-of select="key('validPLAkeys', 'B1CSH0051C')" />
</xsl:for-each>
<!-- <xsl:variable name="validPLAIDs" select="document('B1CSHValidPLA.xml')//ValidPLA" /> -->
<!-- <xsl:value-of select="$validPLAIDs" /> -->
<xsl:value-of select="count(document('B1CSHValidPLA.xml')//ValidPLA)" />


<!-- output header info -->
<xsl:text disable-output-escaping="yes"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>]]></xsl:text>

<xsl:text disable-output-escaping="yes"><![CDATA[<Rows>]]></xsl:text>

<xsl:for-each select="document('SamplePeopleSoft.xml')/Rows/Row">

<xsl:variable name="subacct"> <xsl:value-of select="SubAccount" /> </xsl:variable>
<xsl:value-of select="$subacct" />

<xsl:text disable-output-escaping="yes"><![CDATA[<Row>]]></xsl:text>

<!-- invoke templates to copy the child nodes -->
<!-- <xsl:copy-of select="child::*" /> -->
<!--
<xsl:apply-templates select="Ledger"/>
<xsl:apply-templates select="BusinessUnit"/>
<xsl:apply-templates select="Dept"/>
<xsl:apply-templates select="Office"/>
<xsl:apply-templates select="Account"/>
<xsl:apply-templates select="Descr"/>
<xsl:apply-templates select="GAAPID"/>
<xsl:apply-templates select="GAAPDescription"/>
<xsl:apply-templates select="SubAccount"/>
<xsl:apply-templates select="ForeignCcyCode"/>
<xsl:apply-templates select="LTDForeignCcyAmt"/>
<xsl:apply-templates select="BaseCcyCode"/>
<xsl:apply-templates select="LTDBaseCcyAmt"/>
<xsl:apply-templates select="Year"/>
<xsl:apply-templates select="Period"/>
-->

<xsl:text disable-output-escaping="yes"><![CDATA[</Row>]]></xsl:text>


</xsl:for-each>

<xsl:text disable-output-escaping="yes"><![CDATA[</Rows>]]></xsl:text>

</xsl:template>

<xsl:template match="Ledger">
<xsl:text disable-output-escaping="yes"><![CDATA[<LEDGER>]]></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes"><![CDATA[</Ledger>]]></xsl:text>
</xsl:template>

<xsl:template match="BusinessUnit">
<xsl:text disable-output-escaping="yes"><![CDATA[<BusinessUnit>]]></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes"><![CDATA[</BusinessUnit>]]></xsl:text>
</xsl:template>

<xsl:template match="Dept">
<xsl:text disable-output-escaping="yes"><![CDATA[<Dept>]]></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes"><![CDATA[</Dept>]]></xsl:text>
</xsl:template>

<xsl:template match="Office">
<xsl:text disable-output-escaping="yes"><![CDATA[<Office>]]></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes"><![CDATA[</Office>]]></xsl:text>
</xsl:template>

<xsl:template match="Account">
<xsl:text disable-output-escaping="yes"><![CDATA[<Account>]]></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes"><![CDATA[</Account>]]></xsl:text>
</xsl:template>

<xsl:template match="Descr">
<xsl:text disable-output-escaping="yes"><![CDATA[<Descr>]]></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes"><![CDATA[</Descr>]]></xsl:text>
</xsl:template>

<xsl:template match="GAAPID">
<xsl:text disable-output-escaping="yes"><![CDATA[<GAAPID>]]></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes"><![CDATA[</GAAPID>]]></xsl:text>
</xsl:template>

<xsl:template match="GAAPDescription">
<xsl:text disable-output-escaping="yes"><![CDATA[<GAAPDescription>]]></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes"><![CDATA[</GAAPDescription>]]></xsl:text>
</xsl:template>

<xsl:template match="LedgerCode">
<xsl:text disable-output-escaping="yes"><![CDATA[<LedgerCode>]]></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes"><![CDATA[</LedgerCode>]]></xsl:text>
</xsl:template>

<xsl:template match="SubAccount">
<xsl:text disable-output-escaping="yes"><![CDATA[<SubAccount>]]></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes"><![CDATA[</SubAccount>]]></xsl:text>
</xsl:template>

<xsl:template match="ForeignCcyCode">
<xsl:text disable-output-escaping="yes"><![CDATA[<ForeignCcyCode>]]></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes"><![CDATA[</ForeignCcyCode>]]></xsl:text>
</xsl:template>

<xsl:template match="LTDForeignCcyAmt">
<xsl:text disable-output-escaping="yes"><![CDATA[<LTDForeignCcyAmt>]]></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes"><![CDATA[</LTDForeignCcyAmt>]]></xsl:text>
</xsl:template>

<xsl:template match="BaseCcyCode">
<xsl:text disable-output-escaping="yes"><![CDATA[<BaseCcyCode>]]></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes"><![CDATA[</BaseCcyCode>]]></xsl:text>
</xsl:template>

<xsl:template match="LTDBaseCcyAmt">
<xsl:text disable-output-escaping="yes"><![CDATA[<LTDBaseCcyAmt>]]></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes"><![CDATA[</LTDBaseCcyAmt>]]></xsl:text>
</xsl:template>

<xsl:template match="Year">
<xsl:text disable-output-escaping="yes"><![CDATA[<Year>]]></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes"><![CDATA[</Year>]]></xsl:text>
</xsl:template>

<xsl:template match="Period">
<xsl:text disable-output-escaping="yes"><![CDATA[<Period>]]></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes"><![CDATA[</Period>]]></xsl:text>
</xsl:template>

</xsl:stylesheet>

Im using MSXSL 4.0 to test.

thks in advance.
Lee!
 
Old November 19th, 2010, 04:31 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

A couple of things.

Firstly, all that use of CDATA and disable-output-escaping looks very wrong. It usually means you have misunderstood something, especially if you are trying to output XML declarations using it.

Secondly, you haven't told us what you actually want your output to look like. The actual bit in the root template looks correct in terms of your use of key() within a xsl:for-each instruction, but you don't do anything with the result other than output its value.

Finally, I see no link between the value in file 1 (e.g. D4P8) to the value you highlight in file 2 (e.g. B1CSH0044C).
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old November 19th, 2010, 03:48 PM
Registered User
 
Join Date: Nov 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation update info for my sample Xml +Xslt

Thanks, sir, for the prompt reply. The Xml snippets I posted were not the best illustrations. Improvements are below.
A sample of expected output :

Code:
<?xml version="1.0" encoding="UTF-8"?>
<Rows>
	<Row>
		<Ledger>xyz</Ledger>
		<BusinessUnit>xyz</BusinessUnit>
		<Dept>xyz</Dept>
		<Office>xyz</Office>
		<Account>xyz</Account>
		<Descr>xyz</Descr>
		<GAAPID>xyz</GAAPID>
		<GAAPDescription>xyz</GAAPDescription>
		<LedgerCode>xyz</LedgerCode>
		<SubAccount>D4P8</SubAccount>
		<ForeignCcyCode>xyz</ForeignCcyCode>
		<LTDForeignCcyAmt>xyz</LTDForeignCcyAmt>
		<BaseCcyCode>xyz</BaseCcyCode>
		<LTDBaseCcyAmt>xyz</LTDBaseCcyAmt>
		<Year>xyz</Year>
		<Period>xyz</Period>
	</Row>
I use the CDATA and disable-output-escaping, because using :
<xsl:copy-of select="child::*" /> rather than the apply-templates, output
unwanted NameSpace URIs, so to recreate the output <Xml> tags I found this workaround.
the only coding issue I have is applying the (file2) B1CSHValidPLA.xml:ValidPLA key values to test a match with (file1) SamplePeopleSoft.xml:SubAccount to trigger the output of that <Row>.
I cant figure out yet how to merge the checking of the ValidPLA key value in file2 to the file1 <Row>/SubAccount value parsed in the root template??
Im sure this is a common enough usecase for Xlst, I would appreciate help with getting it to *wrox* thks! Lee

refresh of Xml+Xslt samples:

<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="B1CSHValidPLA.xsd" generated="2010-11-04T07:30:00">
<B1CSHValidPLA>
<ID>1</ID>
<ValidPLA>D4P8</ValidPLA>
</B1CSHValidPLA>
<B1CSHValidPLA>
<ID>2</ID>
<ValidPLA>XYZ</ValidPLA>
</B1CSHValidPLA>
<B1CSHValidPLA>
<ID>3</ID>
<ValidPLA>XYZ</ValidPLA>
</B1CSHValidPLA>
</dataroot>

<?xml version="1.0" encoding="UTF-8"?>
<Rows>
<Row>
<Ledger>XYX</Ledger>
<BusinessUnit>XYX</BusinessUnit>
<Dept>XYX</Dept>
<Office>XYX</Office>
<Account>XYX</Account>
<Descr>XYX</Descr>
<GAAPID>XYX</GAAPID>
<GAAPDescription>XYX</GAAPDescription>
<LedgerCode> LOCAL</LedgerCode>
<SubAccount>D4P8</SubAccount>
<ForeignCcyCode>XYX</ForeignCcyCode>
<LTDForeignCcyAmt>XYX</LTDForeignCcyAmt>
<BaseCcyCode>XYX</BaseCcyCode>
<LTDBaseCcyAmt>XYX</LTDBaseCcyAmt>
<Year>XYX</Year>
<Period>XYX</Period>
</Row>
<Row>
<Ledger>XYX</Ledger>
<BusinessUnit>XYX</BusinessUnit>
<Dept>XYX</Dept>
<Office>XYX</Office>
<Account>XYX</Account>
<Descr>XYX</Descr>
<GAAPID>XYX</GAAPID>
<GAAPDescription>XYX</GAAPDescription>
<LedgerCode>XYX</LedgerCode>
<SubAccount> D1MW</SubAccount>
<ForeignCcyCode>XYX</ForeignCcyCode>
<LTDForeignCcyAmt>XYX</LTDForeignCcyAmt>
<BaseCcyCode>XYX</BaseCcyCode>
<LTDBaseCcyAmt>XYX</LTDBaseCcyAmt>
<Year>XYX</Year>
<Period>XYX</Period>
</Row>
</Rows>
 
Old November 19th, 2010, 05:30 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Firstly, to exclude unused namespaces, use the exclude-result-prefixes attribute on the xsl:stylesheet instruction.

I would recommend declaring a global variable to hold the second document like this:

<xsl:variable name="doc" select="document('B1CSHValidPLA.xml')"/>

And define a key to do the lookup:

<xsl:key name="refKey" pattern="B1CSHValidPLA" use="ValidPLA"/>

Then if you want to know if want to know if a subaccount exists like this:

Code:
<xsl:template match="Row">
<xsl:variable name="row" select="."/>
<xsl:variable name="exists">
  <xsl:for-each select="$doc">
    <xsl:value-of select="key('refKey', $row/SubAccount)"/>  
  </xsl:for-each>
</xsl:variable>
<xsl:if test="$exists">
  <Row>
   ... do everything
  </Row>
</xsl:if>
</xsl:template>
Not 100% sure this is what you want but hopefully it gives you some help.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old November 19th, 2010, 06:25 PM
Registered User
 
Join Date: Nov 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default $exists or not $exists...

Hey, thanks, Sam, for your template help and sugg, for a newbee..

Your suggestion looks good, but the $exists if test always returns positive, even if neither subAccount key (ie. D4P8 or D1MW) exists in 'B1CSHValidPLA.xml' and I get both somePeopleSoft.xml Rows output ...
<xsl:value-of select="$row/SubAccount" /> --> prints the subAccount key as expected, but <xsl:value-of select="$exists" /> --> no output!
Any idea there? ps. i have XmlSpy, will try to figure out the Xlst debugger.


-- new xlst template --
Code:
<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />


	<!-- declare a global variable to hold the second document -->
	<xsl:variable name="doc" select="document('B1CSHValidPLA.xml')" />
	<!-- Define a key to do the lookup:   -->
	<xsl:key name="refKey" match="B1CSHValidPLA" use="ValidPLA" />

	<!--  	<xsl:key name="validPLAkeys" match="B1CSHValidPLA" use="ValidPLA"/>   -->

	<xsl:template match="Row">
		<xsl:variable name="row" select="." />

		<xsl:variable name="exists">
			<xsl:for-each select="$doc">
				<xsl:value-of select="key('refKey', $row/SubAccount)" />
			</xsl:for-each>
		</xsl:variable>

<xsl:value-of select="$exists" />
<xsl:value-of select="$row/SubAccount" />

		<xsl:if test="$exists">
			<Row>
 
				<xsl:apply-templates select="Ledger" />
<!-- 
				<xsl:apply-templates select="BusinessUnit" />
				<xsl:apply-templates select="Dept" />
				<xsl:apply-templates select="Office" />
				<xsl:apply-templates select="Account" />
				<xsl:apply-templates select="Descr" />
				<xsl:apply-templates select="GAAPID" />
				<xsl:apply-templates select="GAAPDescription" />
				<xsl:apply-templates select="SubAccount" />
				<xsl:apply-templates select="ForeignCcyCode" />
				<xsl:apply-templates select="LTDForeignCcyAmt" />
				<xsl:apply-templates select="BaseCcyCode" />
				<xsl:apply-templates select="LTDBaseCcyAmt" />
				<xsl:apply-templates select="Year" />
				<xsl:apply-templates select="Period" />
-->
			</Row>
		</xsl:if>
	</xsl:template>




	<xsl:template match="Ledger">
		<xsl:text disable-output-escaping="yes"><![CDATA[<LEDGER>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</Ledger>]]></xsl:text>
	</xsl:template>

	<xsl:template match="BusinessUnit">
		<xsl:text disable-output-escaping="yes"><![CDATA[<BusinessUnit>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</BusinessUnit>]]></xsl:text>
	</xsl:template>

	<xsl:template match="Dept">
		<xsl:text disable-output-escaping="yes"><![CDATA[<Dept>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</Dept>]]></xsl:text>
	</xsl:template>

	<xsl:template match="Office">
		<xsl:text disable-output-escaping="yes"><![CDATA[<Office>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</Office>]]></xsl:text>
	</xsl:template>

	<xsl:template match="Account">
		<xsl:text disable-output-escaping="yes"><![CDATA[<Account>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</Account>]]></xsl:text>
	</xsl:template>

	<xsl:template match="Descr">
		<xsl:text disable-output-escaping="yes"><![CDATA[<Descr>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</Descr>]]></xsl:text>
	</xsl:template>

	<xsl:template match="GAAPID">
		<xsl:text disable-output-escaping="yes"><![CDATA[<GAAPID>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</GAAPID>]]></xsl:text>
	</xsl:template>

	<xsl:template match="GAAPDescription">
		<xsl:text disable-output-escaping="yes"><![CDATA[<GAAPDescription>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</GAAPDescription>]]></xsl:text>
	</xsl:template>

	<xsl:template match="LedgerCode">
		<xsl:text disable-output-escaping="yes"><![CDATA[<LedgerCode>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</LedgerCode>]]></xsl:text>
	</xsl:template>

	<xsl:template match="SubAccount">
		<xsl:text disable-output-escaping="yes"><![CDATA[<SubAccount>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</SubAccount>]]></xsl:text>
	</xsl:template>

	<xsl:template match="ForeignCcyCode">
		<xsl:text disable-output-escaping="yes"><![CDATA[<ForeignCcyCode>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</ForeignCcyCode>]]></xsl:text>
	</xsl:template>

	<xsl:template match="LTDForeignCcyAmt">
		<xsl:text disable-output-escaping="yes"><![CDATA[<LTDForeignCcyAmt>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</LTDForeignCcyAmt>]]></xsl:text>
	</xsl:template>

	<xsl:template match="BaseCcyCode">
		<xsl:text disable-output-escaping="yes"><![CDATA[<BaseCcyCode>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</BaseCcyCode>]]></xsl:text>
	</xsl:template>

	<xsl:template match="LTDBaseCcyAmt">
		<xsl:text disable-output-escaping="yes"><![CDATA[<LTDBaseCcyAmt>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</LTDBaseCcyAmt>]]></xsl:text>
	</xsl:template>

	<xsl:template match="Year">
		<xsl:text disable-output-escaping="yes"><![CDATA[<Year>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</Year>]]></xsl:text>
	</xsl:template>

	<xsl:template match="Period">
		<xsl:text disable-output-escaping="yes"><![CDATA[<Period>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</Period>]]></xsl:text>
	</xsl:template>



</xsl:stylesheet>
 
Old November 19th, 2010, 06:54 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Perhaps try changing it for $exists <> ''
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old November 21st, 2010, 11:25 AM
Registered User
 
Join Date: Nov 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default $exists<> ?

syntax error...
The character '<' cannot be used in an attribute value.
 
Old November 21st, 2010, 12:36 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

OK, it's !=
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old November 22nd, 2010, 10:51 AM
Registered User
 
Join Date: Nov 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default syntax error

do you mean to use: <xsl:if test!="$exists">
invalid character syntax error. :(
is it possible for you to try this xslt template against my sample xmls?
thks!

Code:
<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />


	<!-- declare a global variable to hold the second document -->
	<xsl:variable name="doc" select="document('B1CSHValidPLA.xml')" />
	<!-- Define a key to do the lookup:   -->
	<xsl:key name="refKey" match="B1CSHValidPLA" use="ValidPLA" />

	<!--  	<xsl:key name="validPLAkeys" match="B1CSHValidPLA" use="ValidPLA"/>   -->

	<xsl:template match="Row">
		<xsl:variable name="row" select="." />

		<xsl:variable name="exists">
			<xsl:for-each select="$doc">
				<xsl:value-of select="key('refKey', $row/SubAccount)" />
			</xsl:for-each>
		</xsl:variable>


<xsl:value-of select="$row/SubAccount" />

		<xsl:if test="$exists">
			<Row>
 
				<xsl:apply-templates select="Ledger" />
<!-- 
				<xsl:apply-templates select="BusinessUnit" />
				<xsl:apply-templates select="Dept" />
				<xsl:apply-templates select="Office" />
				<xsl:apply-templates select="Account" />
				<xsl:apply-templates select="Descr" />
				<xsl:apply-templates select="GAAPID" />
				<xsl:apply-templates select="GAAPDescription" />
				<xsl:apply-templates select="SubAccount" />
				<xsl:apply-templates select="ForeignCcyCode" />
				<xsl:apply-templates select="LTDForeignCcyAmt" />
				<xsl:apply-templates select="BaseCcyCode" />
				<xsl:apply-templates select="LTDBaseCcyAmt" />
				<xsl:apply-templates select="Year" />
				<xsl:apply-templates select="Period" />
-->
			</Row>
		</xsl:if>
	</xsl:template>




	<xsl:template match="Ledger">
		<xsl:text disable-output-escaping="yes"><![CDATA[<LEDGER>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</Ledger>]]></xsl:text>
	</xsl:template>

	<xsl:template match="BusinessUnit">
		<xsl:text disable-output-escaping="yes"><![CDATA[<BusinessUnit>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</BusinessUnit>]]></xsl:text>
	</xsl:template>

	<xsl:template match="Dept">
		<xsl:text disable-output-escaping="yes"><![CDATA[<Dept>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</Dept>]]></xsl:text>
	</xsl:template>

	<xsl:template match="Office">
		<xsl:text disable-output-escaping="yes"><![CDATA[<Office>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</Office>]]></xsl:text>
	</xsl:template>

	<xsl:template match="Account">
		<xsl:text disable-output-escaping="yes"><![CDATA[<Account>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</Account>]]></xsl:text>
	</xsl:template>

	<xsl:template match="Descr">
		<xsl:text disable-output-escaping="yes"><![CDATA[<Descr>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</Descr>]]></xsl:text>
	</xsl:template>

	<xsl:template match="GAAPID">
		<xsl:text disable-output-escaping="yes"><![CDATA[<GAAPID>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</GAAPID>]]></xsl:text>
	</xsl:template>

	<xsl:template match="GAAPDescription">
		<xsl:text disable-output-escaping="yes"><![CDATA[<GAAPDescription>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</GAAPDescription>]]></xsl:text>
	</xsl:template>

	<xsl:template match="LedgerCode">
		<xsl:text disable-output-escaping="yes"><![CDATA[<LedgerCode>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</LedgerCode>]]></xsl:text>
	</xsl:template>

	<xsl:template match="SubAccount">
		<xsl:text disable-output-escaping="yes"><![CDATA[<SubAccount>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</SubAccount>]]></xsl:text>
	</xsl:template>

	<xsl:template match="ForeignCcyCode">
		<xsl:text disable-output-escaping="yes"><![CDATA[<ForeignCcyCode>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</ForeignCcyCode>]]></xsl:text>
	</xsl:template>

	<xsl:template match="LTDForeignCcyAmt">
		<xsl:text disable-output-escaping="yes"><![CDATA[<LTDForeignCcyAmt>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</LTDForeignCcyAmt>]]></xsl:text>
	</xsl:template>

	<xsl:template match="BaseCcyCode">
		<xsl:text disable-output-escaping="yes"><![CDATA[<BaseCcyCode>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</BaseCcyCode>]]></xsl:text>
	</xsl:template>

	<xsl:template match="LTDBaseCcyAmt">
		<xsl:text disable-output-escaping="yes"><![CDATA[<LTDBaseCcyAmt>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</LTDBaseCcyAmt>]]></xsl:text>
	</xsl:template>

	<xsl:template match="Year">
		<xsl:text disable-output-escaping="yes"><![CDATA[<Year>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</Year>]]></xsl:text>
	</xsl:template>

	<xsl:template match="Period">
		<xsl:text disable-output-escaping="yes"><![CDATA[<Period>]]></xsl:text>
		<xsl:value-of select="." />
		<xsl:text disable-output-escaping="yes"><![CDATA[</Period>]]></xsl:text>
	</xsl:template>



</xsl:stylesheet>
 
Old November 22nd, 2010, 12:02 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

No, sorry, I meant <xsl:if test="$exists!=''">
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Howto get subchild from xml file hacking_mike Javascript How-To 7 March 25th, 2010 09:58 AM
Converting delimited text to separate XML Elements tcblack XSLT 5 March 18th, 2010 06:02 PM
separate file location for different databases Aprile MySQL 1 September 6th, 2007 04:34 PM
file upload processed on separate page vauneen ASP.NET 2.0 Professional 0 August 8th, 2006 03:03 AM
howto test document exists folklayer XSLT 2 October 19th, 2005 05:56 PM





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