Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need help with 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 and


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

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

Example output :



m
63
728


ul
3
137


in
PASS
1526




SQ
62
728


MT
3
137


LT
FAIL
1526





You can see in above example If I am taking the Units from my 2nd section of xml
and I want to take the <<value>> from 1st section of input xml 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


ul
68
137


in
2
1526




m
1
728


ul
68
137


in
2
1526











Sign In or Register to comment.