Hello,

i´m beginer in XSL and i need help. In attachment, is source xml and my xsl. I have problem with filtering element date. Because, when i run transform result is duplicate.

Can you help me?

thx

Stan

For testing mahe context in pri:prijemkaDetail tag

<?xml version="1.0" encoding="Windows-1250"?>
<rsp:responsePack version="1.2" id="001" state="ok" note="" programVersion="9504.4 (15.7.2010)" xmlns:rsp="http://www.stormware.cz/schema/response.xsd" xmlns:rdc="http://www.stormware.cz/schema/documentresponse.xsd"
                  xmlns:typ="http://www.stormware.cz/schema/type.xsd" xmlns:lst="http://www.stormware.cz/schema/list.xsd" xmlns:acu="http://www.stormware.cz/schema/accountingunit.xsd" xmlns:inv="http://www.stormware.cz/schema/invoice.xsd"
                  xmlns:vch="http://www.stormware.cz/schema/voucher.xsd" xmlns:int="http://www.stormware.cz/schema/intDoc.xsd" xmlns:stk="http://www.stormware.cz/schema/stock.xsd" xmlns:ord="http://www.stormware.cz/schema/order.xsd"
                  xmlns:ofr="http://www.stormware.cz/schema/offer.xsd" xmlns:enq="http://www.stormware.cz/schema/enquiry.xsd" xmlns:vyd="http://www.stormware.cz/schema/vydejka.xsd" xmlns:pri="http://www.stormware.cz/schema/prijemka.xsd"
                  xmlns:bal="http://www.stormware.cz/schema/balance.xsd" xmlns:pre="http://www.stormware.cz/schema/prevodka.xsd" xmlns:vyr="http://www.stormware.cz/schema/vyroba.xsd" xmlns:pro="http://www.stormware.cz/schema/prodejka.xsd"
                  xmlns:con="http://www.stormware.cz/schema/contract.xsd" xmlns:adb="http://www.stormware.cz/schema/addressbook.xsd" xmlns:prm="http://www.stormware.cz/schema/parameter.xsd" xmlns:lst2="http://www.stormware.cz/schema/list_2.xsd"
                  xmlns:ctg="http://www.stormware.cz/schema/category.xsd" xmlns:ipm="http://www.stormware.cz/schema/intParam.xsd">
	<rsp:responsePackItem version="1.0" id="pri_01" state="ok">
		<lst:listPrijemka version="1.1" dateTimeStamp="2011-01-30T22:26:52Z" dateValidFrom="2011-01-30" state="ok">
			<lst:prijemka version="1.6">
				<pri:prijemkaHeader>
					<pri:id>5</pri:id>
					<pri:number>
						<typ:id>128</typ:id>
						<typ:ids>10SP</typ:ids>
						<typ:numberRequested>10SP00004</typ:numberRequested>
					</pri:number>
					<pri:date>2010-10-16</pri:date>
					<pri:text>Príjemka k faktúre č.</pri:text>
					<pri:partnerIdentity>
						<typ:id>58</typ:id>
						<typ:address>
							<typ:company>DOPRAVOSPOL spol.s r.o.</typ:company>
							<typ:city>Bytča</typ:city>
							<typ:street>Šoltésovej 1684/198</typ:street>
							<typ:zip>014 01</typ:zip>
							<typ:ico>00652261</typ:ico>
							<typ:dic>SK2020182299</typ:dic>
						</typ:address>
					</pri:partnerIdentity>
				</pri:prijemkaHeader>
				<pri:prijemkaDetail>test1</pri:prijemkaDetail>
				<pri:prijemkaSummary>
					<pri:roundingDocument>none</pri:roundingDocument>
					<pri:roundingVAT>none</pri:roundingVAT>
					<pri:homeCurrency>
						<typ:priceNone>0</typ:priceNone>
						<typ:priceLow>0</typ:priceLow>
						<typ:priceLowVAT>0</typ:priceLowVAT>
						<typ:priceLowSum>0</typ:priceLowSum>
						<typ:priceHigh>99.58</typ:priceHigh>
						<typ:priceHighVAT>18.92</typ:priceHighVAT>
						<typ:priceHighSum>118.5</typ:priceHighSum>
						<typ:price3>0</typ:price3>
						<typ:price3VAT>0</typ:price3VAT>
						<typ:price3Sum>0</typ:price3Sum>
						<typ:round>
							<typ:priceRound>0</typ:priceRound>
						</typ:round>
					</pri:homeCurrency>
				</pri:prijemkaSummary>
			</lst:prijemka>
			<lst:prijemka version="1.6">
				<pri:prijemkaHeader>
					<pri:id>6</pri:id>
					<pri:number>
						<typ:id>128</typ:id>
						<typ:ids>10SP</typ:ids>
						<typ:numberRequested>10SP00005</typ:numberRequested>
					</pri:number>
					<pri:date>2010-10-16</pri:date>
					<pri:text>Príjemka k faktúre č.</pri:text>
					<pri:partnerIdentity>
						<typ:id>39</typ:id>
						<typ:address>
							<typ:company>AUTOTIP</typ:company>
							<typ:name>Božena Kačíková</typ:name>
							<typ:city>Bratislava</typ:city>
							<typ:street>tř. T.Bati</typ:street>
							<typ:zip>831 03</typ:zip>
							<typ:ico>30182531</typ:ico>
							<typ:dic>SK2020228879</typ:dic>
						</typ:address>
					</pri:partnerIdentity>
				</pri:prijemkaHeader>
				<pri:prijemkaDetail>test2</pri:prijemkaDetail>
				<pri:prijemkaSummary>
					<pri:roundingDocument>none</pri:roundingDocument>
					<pri:roundingVAT>none</pri:roundingVAT>
					<pri:homeCurrency>
						<typ:priceNone>0</typ:priceNone>
						<typ:priceLow>0</typ:priceLow>
						<typ:priceLowVAT>0</typ:priceLowVAT>
						<typ:priceLowSum>0</typ:priceLowSum>
						<typ:priceHigh>84.48</typ:priceHigh>
						<typ:priceHighVAT>16.05</typ:priceHighVAT>
						<typ:priceHighSum>100.53</typ:priceHighSum>
						<typ:price3>0</typ:price3>
						<typ:price3VAT>0</typ:price3VAT>
						<typ:price3Sum>0</typ:price3Sum>
						<typ:round>
							<typ:priceRound>0</typ:priceRound>
						</typ:round>
					</pri:homeCurrency>
				</pri:prijemkaSummary>
			</lst:prijemka>
		</lst:listPrijemka>
	</rsp:responsePackItem>
</rsp:responsePack>

At define in output result a root element

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"
                xmlns:dat="http://www.stormware.cz/schema/data.xsd" xmlns:pri="http://www.stormware.cz/schema/prijemka.xsd" xmlns:typ="http://www.stormware.cz/schema/type.xsd" xmlns:rsp="http://www.stormware.cz/schema/response.xsd"
                xmlns:lst="http://www.stormware.cz/schema/list.xsd">
	<xsl:output method="xml" indent="yes" encoding="UTF-8"/>	
	<xsl:template match="text()|@*">
		 <!-- do nothing -->
	</xsl:template>	
	<xsl:template match="/">
		<root>
			<pri:prijemkaHeader>
				<xsl:apply-templates select="//pri:prijemkaHeader"/>
			</pri:prijemkaHeader>

			<pri:prijemkaDetail>
				<xsl:apply-templates select="//pri:prijemkaDetail"/>
			</pri:prijemkaDetail>
		</root>
	</xsl:template>
	<xsl:template match="pri:prijemkaHeader">
		<xsl:apply-templates/>
	</xsl:template>
	<xsl:template match="pri:date">
		<xsl:element name="pri:date">
			<xsl:value-of select="."/>
		</xsl:element>
	</xsl:template>
	<xsl:template match="pri:prijemkaDetail">
		<xsl:element name="pri:detail">
			<xsl:value-of select="."/>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>

result

<?xml version='1.0' encoding='UTF-8' ?>
<root xmlns:rsp="http://www.stormware.cz/schema/response.xsd" xmlns:lst="http://www.stormware.cz/schema/list.xsd" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:typ="http://www.stormware.cz/schema/type.xsd" xmlns:pri="http://www.stormware.cz/schema/prijemka.xsd" xmlns:dat="http://www.stormware.cz/schema/data.xsd">
  <pri:prijemkaHeader>
    <pri:date>2010-10-16</pri:date>
    <pri:date>2010-10-16</pri:date>
  </pri:prijemkaHeader>
  <pri:prijemkaDetail>
    <pri:detail>test1</pri:detail>
    <pri:detail>test2</pri:detail>
  </pri:prijemkaDetail>
</root>

not use for-each when is easy o walk in the tree

thanks

you wrote not use for-each when is easy o walk in the tree, but when i want pri:date for each typ:id, how can i do that?

go in tag pri:id
then with xpath go back and select pri:date

pri:prijemkaHeader -#- pri:id = 6   your here with ../pri:date
                    #- pri:number -#- typ:id = 128
                    #              #- typ:ids = 10SP
                    #              #- typ:numberRequested = 10SP00005
                    #- pri:date = 2010-10-16 then select here
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"
                xmlns:dat="http://www.stormware.cz/schema/data.xsd" xmlns:pri="http://www.stormware.cz/schema/prijemka.xsd" xmlns:typ="http://www.stormware.cz/schema/type.xsd" xmlns:rsp="http://www.stormware.cz/schema/response.xsd"
                xmlns:lst="http://www.stormware.cz/schema/list.xsd">
	<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
	<xsl:template match="text()|@*">
		<!-- do nothing -->
	</xsl:template>
	<xsl:template match="/">
		<root>
			<pri:prijemkaHeader>
				<xsl:apply-templates select="//pri:prijemkaHeader"/>
			</pri:prijemkaHeader>

			<pri:prijemkaDetail>
				<xsl:apply-templates select="//pri:prijemkaDetail"/>
			</pri:prijemkaDetail>
		</root>
	</xsl:template>
	<xsl:template match="pri:prijemkaHeader">
		<xsl:apply-templates/>
	</xsl:template>
	<xsl:template match="pri:id">
		<xsl:element name="pri:date">
			<xsl:value-of select="../pri:date"/>
		</xsl:element>
	</xsl:template>
	<!--
	<xsl:template match="pri:date">
		<xsl:element name="pri:date">
			<xsl:value-of select="."/>
		</xsl:element>
	</xsl:template>
	-->
	<xsl:template match="pri:prijemkaDetail">
		<xsl:element name="pri:detail">
			<xsl:value-of select="."/>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>

thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.