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 December 2nd, 2009, 05:48 PM
Registered User
 
Join Date: Dec 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default need help xslt

Hi,

I need some help in xslt. I am trying to develop a xslt , I have pasted the short format of all 3 files below, The Input xml file. The xslt and output xml.
I will be very great full If anybody can help. I have tried everything but no luck. I am using @@@@ for comment or to explain in below files.


If you see my xml file I have 2 section in the xml <Partcase1> and <Testlot>


From the <Case1row> i want last 3 rows of data. But not from the first module , I want the data from second section of <Case1row>
example : (63,3,PASS) and (62,3,PASS) @@@@@@@@@@---these are located in property/data see below-Last2 sections in <case1row>--@@@@@@@@@@@@@@

I want these 3 values to be picked up and show in my output xml for parameters.

Example output :

<Parameters>
<Parameter>
<unit>m</unit>
<Value>63</Value>
<code>728</code>
</Parameter>
<Parameter>
<unit>ul</unit>
<Value>3</Value>
<code>137</code>
</Parameter>
<Parameter>
<unit>in</unit>
<Value>PASS</Value>
<code>1526</code>
</Parameter>
</Parameters>
<Parameters>
<Parameter>
<unit>SQ</unit>
<measurementValue>62</measurementValue>
<code>728</code>
</Parameter>
<Parameter>
<unit>MT</unit>
<Value>3</Value>
<code>137</code>
</Parameter>
<Parameter>
<unit>LT</unit>
<Value>FAIL</Value>
<code>1526</code>
</Parameter>
</Parameters>



You can see in above example If I am taking the Units from my 2nd section of xml <testlot>
and I want to take the <<value>> from 1st section of input xml <Case1row> and <<Code>> as you can see I hardcoded it in xslt.

Can anybody help me out with this


@@@@@@@@@@@@@@----My XML File : @@@@@@@@@@@@@@@@

<xml>
<parent>
<certificate>
<content>
<block >
<partcase1>
<case1>
<case1data>
<case1row >
<property><data> LNumber: </data></property>
<property><data> Date: </data></property>
<property><data>Reading</data></property>
<property><data>Disk</data></property>
<property><data>Thickness</data></property>
</case1row >
<case1row >
<property><data> A1 </data></property>
<property><data> 09/03/2009 </data></property>
<property><data>63</data></property>
<property><data>3</data></property>
<property><data>PASS</data></property>
</case1row >
<case1row >
<property><data> A0 </data></property>
<property><data> 09/03/2009 </data></property>
<property><data>62</data></property>
<property><data>3</data></property>
<property><data>FAIL</data></property>
</case1row >
</case1data>
</case1>
</partcase1>
</block>
<testlot>
<lnumber>
<label>LNumber:</label>
<value>A1</value>
<datelabel>Date</datelabel>
<date>09/03/2009</date>
</lnumber>
<aggheader>
<name>Property</name>
<units>Units</units>
<results>Results</results>
</aggheader>
<aggdata>
<namevalue>Reading</namevalue>
<units>m</units>
</aggdata>
<aggdata>
<namevalue>Disk</namevalue>
<units>ul</units>
</aggdata>
<aggdata>
<namevalue>Thickness</namevalue>
<units>in</units>
</aggdata>
</testlot>
<testlot>
<lnumber>
<label>Lnumber</label>
<value>A0</value>
<datelabel>Date</datelabel>
<date>09/03/2009</date>
</lnumber>
<aggheader>
<name>Test Property</name>
<units>Units</units>
<results>Results</results>
</aggheader>
<aggdata>
<namevalue>Reading</namevalue>
<units>SQ</units>
</aggdata>
<aggdata>
<namevalue>Disk</namevalue>
<units>MT</units>
</aggdata>
<aggdata>
<namevalue>Thicknessk</namevalue>
<units>LT</units>
</aggdata>
</testlot>
</content>
</certificate>
</parent>
</xml>

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ XSLT File : ----------@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" indent="yes" />
<xsl:template match="/">
<xsl:element name="File" namespace="x-schema:../Schema/QualityCertificateSchema2001Jul.xml">
<xsl:element name="Sites" namespace="x-schema:../Schema/Certificateschema2001Jul.xml">
<xsl:element name="Description" namespace="x-schema:../Schema/Certificateschema2001Jul.xml">
<xsl:element name="Certificates" namespace="x-schema:../Schema/Certificateschema2001Jul.xml">
<xsl:for-each select="//testlot">
<xsl:variable name="LotNode" select="." />
<xsl:variable name="Lot" select="./lotnumber/value" />
<xsl:element name="Certificate" namespace="x-schema:../Schema/Certificateschema2001Jul.xml">
<xsl:element name="Parameters" namespace="x-schema:../Schema/Certificateschema2001Jul.xml">
<xsl:for-each select="$LotNode/aggregatedresultsdata">
<xsl:variable name="PropertyNode" select="." />
<xsl:variable name="PropertyName" select="$PropertyNode/namevalue" />
<xsl:element name="Parameter" namespace="x-schema:../Schema/Certificateschema2001Jul.xml">
<xsl:element name="unit" namespace="x-schema:../Schema/Certificateschema2001Jul.xml">
<xsl:value-of select="units" />
</xsl:element>
<xsl:element name="measurementValue" namespace="x-schema:../Schema/Certificateschema2001Jul.xml">
<xsl:variable name="aggdisp" select="//testlot/@aggrDisp"/>
<xsl:variable name="data1" select="//partcase1/case1/case1data/case1row"/>
<xsl:variable name="data2" select="//partcase2/case1/case1data/case1row"/>
<xsl:variable name="data3" select="//partcase3/case1/case1data/case1row"/>
<xsl:variable name="data4" select="//partcase4/case1/case1data/case1row"/>
<xsl:variable name="Code1" select="$PropertyNode/namevalue" />
<xsl:variable name="datalot1" select="$data1/property/data[. mod 2=1][1]"/>
<xsl:variable name="datalot2" select="$data2/property/data[. mod 3=2][1]"/>
<xsl:variable name="datalot3" select="$data3/property/data[. mod 4=2][1]"/>
<xsl:choose>
<xsl:when test="$Code1='Reading'"><xsl:value-of select="$datalot1"/></xsl:when>
<xsl:when test="$Code1='Disk'"><xsl:value-of select="$datalot2"/></xsl:when>
<xsl:when test="$Code1='Thickness'"><xsl:value-of select="$datalot3"/></xsl:when>
<xsl:otherwise>
<xsl:value-of select="$Code1" />
</xsl:otherwise>
</xsl:choose>
</xsl:element>
<xsl:element name="code" namespace="x-schema:../Schema/Certificateschema2001Jul.xml">
<xsl:variable name="code_agg" select="$PropertyNode/namevalue" />
<xsl:choose>
<xsl:when test="$code_agg='Property'">test</xsl:when>
<xsl:when test="$code_agg='Flatness'">728</xsl:when>
<xsl:when test="$code_agg='Disk'">137</xsl:when>
<xsl:when test="$code_agg='Thickness'">1526</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ---Output file----@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@
I am looking for the output like this

<?xml version="1.0" encoding="utf-8"?>
<File xmlns="x-schema:../Schema/QualityCertificateSchema2001Jul.xml">
<Sites>
<Description>
<manufacturerNumber>006173082</manufacturerNumber>
<Certificates>
<certificate="Single">
<Description>
<pName>MA</pName>
<Part>1519-8</Part>
<Order>A_A1</Order>
<lNumber>A1</lNumber>
</Description>
<Parameters>
<Parameter>
<unit>m</unit>
<measurementValue>1</measurementValue>
<code>728</code>
</Parameter>
<Parameter>
<unit>ul</unit>
<Value>68</Value>
<code>137</code>
</Parameter>
<Parameter>
<unit>in</unit>
<Value>2</Value>
<code>1526</code>
</Parameter>
</Parameters>
<Parameters>
<Parameter>
<unit>m</unit>
<measurementValue>1</measurementValue>
<code>728</code>
</Parameter>
<Parameter>
<unit>ul</unit>
<Value>68</Value>
<code>137</code>
</Parameter>
<Parameter>
<unit>in</unit>
<Value>2</Value>
<code>1526</code>
</Parameter>
</Parameters>
</Certificate>
</Certificates>
</Description>
</Sites>
</File>
 
Old December 2nd, 2009, 06:07 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm sorry, I can't understand the relationship between your input and your desired output. Your desired output contains numbers like 728 and 1526 which don't seem to relate to anything in the input.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old December 3rd, 2009, 10:50 AM
Registered User
 
Join Date: Dec 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Thanks for the reply,

As you can see I have hardcoded these in the xslt.

<xsl:variable name="code_agg" select="$PropertyNode/namevalue" />
<xsl:choose>
<xsl:when test="$code_agg='Property'">test</xsl:when>
<xsl:when test="$code_agg='Flatness'">728</xsl:when>
<xsl:when test="$code_agg='Disk'">137</xsl:when>
<xsl:when test="$code_agg='Thickness'">1526</xsl:when>
<xsl:otherwise>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Another question about generating XSLT with XSLT danblick XSLT 2 July 16th, 2009 08:40 PM
Generating XSLT with XSLT stonis XSLT 3 April 1st, 2008 08:17 PM
General XSLT Questions in the XSLT Forum jminatel BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 0 March 31st, 2008 07:50 PM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM





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