Project

Profile

Help

need help in xslt

Added by Anonymous almost 15 years ago

Legacy ID: #7448348 Legacy Poster: tech za (techza)

Hello, I have a xml file below from which I want to extract the data using xslt. I am trying to create the xslt but no results , I have some hardcoated values in the xslt which I want in the output xml. I also need the other values from the below xml. But I don't know how to saperate the special characterss. I want to display the date from the below xml , the last 2 lines in my xml has the date value with the special characters in between them, I don't know how to select it and display in the output xml. Kindly help XML File : <DATA> <TEST_NAME="null" CTO_ZZZ_ID="null" SHIP_DATE="" INVOICE_NUMBER="AT45748" TEST_XML_DATA="&lt;xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;&gt;&#xD;&#xA;&#x9;&lt;parent testType= &quot;T&quot; display=&quot;N &quot; gt;&#xD;&#xA;&#x9;&#x9;&lt; preview&gt;&lt;/preview&gt;&#xD;&#xA;&#x9;&lt; testificate&gt;&#xD;&#xA;&#x9;&lt; invoicelabel&gt;Invoice Number: &lt;/invoicelabel&gt;&#xD;&#xA;&#x9;&lt; invoicenumber&gt;AT45748&lt;/invoicenumber&gt;&#xD;&#xA;&#x9;&lt; stocklabel&gt;Stock Number: &lt;/stocklabel&gt;&#xD;&#xA;&#x9;&lt; iddesc&gt;60-0200-1496-9 3TA98-AF COND 4.25 IN&lt;/iddesc&gt;&#xD;&#xA;&#x9;&lt; testcontent expDisp=&quot;false&quot; testtype=&quot;T&quot; font=&quot;&quot; locale=&quot;en&quot; orderInfoAvlbleFlag=&quot;true&quot; previewFont=&quot;Arial&quot; testCommDisp=&quot;false&quot; cpsiaInvoice=&quot;false&quot; optCommentFlag=&quot;false&quot; &gt;&#xD;&#xA;&#x9;&#x9;&lt;logo&gt;&lt;/logo&gt;&#xD;&#xA;&#x9;&#x9;&lt;testtitle locale=&quot;en&quot;&gt;&#xD;&#xA;&#x9;&#x9;&lt;title&gt;testificate of testing&lt;/title&gt;&#xD;&#xA;&#x9;&#x9;&lt;/testtitle&gt;&#xD;&#xA;&#x9;&#x9;&lt;exception locale=&quot;en&quot;&gt;&#xD;&#xA;&#x9;&#x9;&lt;text&gt;&lt;/text&gt;&#xD;&#xA;&#x9;&#x9;&lt;/exception&gt;&#xD;&#xA;&#x9;&#x9;&lt;locationAddress locale=&quot;en&quot;&gt;&#xD;&#xA;&#x9;&#x9;&lt;firstline1&gt;YYYY&lt;/firstline1&gt;&#xD;&#xA;&#x9;&#x9;&lt;secondline1&gt;Bldg 19-01-usa Rd&lt;/secondline1&gt;&#xD;&#xA;&#x9;&#x9;&lt;thirdline1&gt;usa 55016&lt;/thirdline1&gt;&#xD;&#xA;&#x9;&#x9;&lt;/locationAddress&gt;&#xD;&#xA;&#x9;&#x9;&lt;customerAddress locale=&quot;en&quot;&gt;&#xD;&#xA;&#x9;&#x9;&lt;firstline2&gt;EMA US ACRES&lt;/firstline2&gt;&#xD;&#xA;&#x9;&#x9;&lt;secondline2&gt;2222 AVE&lt;/secondline2&gt;&#xD;&#xA;&#x9;&#x9;&lt;thirdline2&gt;HILLSBORO OR 971245506 &lt;/thirdline2&gt;&#xD;&#xA;&#x9;&#x9;&lt;/customerAddress&gt;&#xD;&#xA;&#x9;&#x9;&lt; testdate locale=&quot;en&quot;&gt;&#xD;&#xA;&#x9;&#x9;&lt;label&gt;Date testificate is prepared:&lt;/label&gt;&#xD;&#xA;&#x9;&#x9;&lt;date&gt;Jun-10-2009&lt;/date&gt;&#xD;&#xA;&#x9;&#x9;&lt;/testdate &gt;&#xD;&#xA;&#x9;&#x9;&lt; ---- 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/testificateSchema2001Jul.xml"> <xsl:element name="FileInfo" namespace="x-schema:../Schema/testificateSchema2001Jul.xml"> <xsl:element name="responsiblePartyEmail" namespace="x-schema:../Schema/ChemGasQualitytestificateSchema2001Jul.xml"></xsl:element> </xsl:element> <xsl:element name="BusinessSites" namespace="x-schema:../Schema/testificateSchema2001Jul.xml"> <xsl:element name="Description" namespace="x-schema:../Schema/testificateSchema2001Jul.xml"> <xsl:element name="manufacturerNumber" namespace="x-schema:../Schema/testificateSchema2001Jul.xml">678748</xsl:element> <xsl:element name="manufacturerName" namespace="x-schema:../Schema/testificateSchema2001Jul.xml">TEST</xsl:element> <xsl:element name="manufacturingPlantCode" namespace="x-schema:../Schema/testificateSchema2001Jul.xml">341403</xsl:element> <!-- <xsl:element name="incomingFaxNumber"></xsl:element> obsolete /--> <!--DUNSPlusFour/--> <xsl:element name="manufacturer" namespace="x-schema:../Schema/testificateSchema2001Jul.xml">TEST1</xsl:element> <xsl:variable name="testingDate" select="//testdate/date" /> <xsl:variable name="testMonth" select="substring(//testdate/date,1,3)" /> <xsl:variable name="testMonthDigits"> <xsl:choose> <xsl:when test="$testMonth='Jan'">01</xsl:when> <xsl:when test="$testMonth='Feb'">02</xsl:when> <xsl:when test="$testMonth='Mar'">03</xsl:when> <xsl:when test="$testMonth='Apr'">04</xsl:when> <xsl:when test="$testMonth='May'">05</xsl:when> <xsl:when test="$testMonth='Jun'">06</xsl:when> <xsl:when test="$testMonth='Jul'">07</xsl:when> <xsl:when test="$testMonth='Aug'">08</xsl:when> <xsl:when test="$testMonth='Sep'">09</xsl:when> <xsl:when test="$testMonth='Oct'">10</xsl:when> <xsl:when test="$testMonth='Nov'">11</xsl:when> <xsl:when test="$testMonth='Dec'">12</xsl:when> <xsl:otherwise> <xsl:value-of select="$testMonth" /> </xsl:otherwise> </xsl:choose> </xsl:variable> </xsl:element> </xsl:element> </xsl:element> </xsl:element> </xsl:template> </xsl:stylesheet>


Replies (1)

RE: need help in xslt - Added by Anonymous almost 15 years ago

Legacy ID: #7449657 Legacy Poster: Michael Kay (mhkay)

This looks like a straight request for XSLT coding help, rather than for Saxon help, which means it really belongs on a forum such as the xsl-list at mulberrytech.com. XML is hierarchic, it's designed so that one XML document can always be nested inside another. But despite this, some people insist on flattening an XML document into a string, by escaping all the markup, before inserting it into another XML document. When this is done, and if you can't change the design, then you have to go through two stages of parsing: first parse the outer XML, then extract the string containing the inner XML, then parse this again. Saxon provides the saxon:parse() extension function to help address this kind of scenario: it allows you to parse the escaped XML held in this case in the TEST_XML_DATA attribute. As for your XSLT, you really don't want all these xsl:element instructions. Use literal result elements instead, you code will be much more readable. That is, change <xsl:element name="File" namespace="x-schema:../Schema/testificateSchema2001Jul.xml"> to <x:File> where the prefix x is bound to the appropriate namespace at the xsl:stylesheet level.

    (1-1/1)

    Please register to reply