xslt - XML, XSL namespaces -


i'm new xml namespaces. made documents , seems work fine, don't know whether i'm using namespaces (which requirement). except html file not valid because off this: "attribute xmlns:xsi not allowed here." , "attribute xmlns:xslformatting not allowed here."

questions: 1. using namespaces? (if not how should reach goal?) 2. how can make xsl producing valid html?

<!doctype html> <html xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xslformatting="urn:xslformatting"> 

xml

    <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet href="invoice.xsl" type="text/xsl"?> <invoice xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"  xsi:schemalocation="http://josefdraslar.cz/ schema.xsd" xmlns="http://josefdraslar.cz/">     <buyerparty>         <name>martin</name>         <surname>vomáčka</surname>         <address1>                 <street>melantrichova</street>                 <number>470/8</number>                 <city>praha</city>                 <postalzone>11000</postalzone>                  </address1>         <contact>             <fastcontact>                 <telephone>327345678</telephone>                 <mobile>608473748</mobile>                 <email>vomacka@gmail.com</email>                 <fax/>             </fastcontact>             <address>                 <street>melantrichova</street>                 <number>470/8</number>                 <city>praha</city>                 <postalzone>11000</postalzone>                  <notes>čtvrté dveře vlevo</notes>             </address>         </contact>         <ico/>     </buyerparty>     <sellerparty>         <name>alza.cz a.s.</name>         <address>             <street>jateční</street>             <number>33a</number>             <city>praha</city>             <postalzone>17000</postalzone>             <notes/>         </address>         <contact>             <telephone>327456709</telephone>             <mobile>607359724</mobile>             <email>info@alza.cz</email>             <fax>225340190</fax>         </contact>         <ico>27082440</ico>         <bankaccount>             <number>2171532</number>             <bank>                 <kode>0800</kode>                 <name>Česká spořitelna</name>             </bank>             <specificsymbol>345723</specificsymbol>         </bankaccount>     </sellerparty>     <invoiceinfo>         <issuedate>01.03.2015</issuedate>         <maturity>30.03.2015</maturity>         <invoicenumber>345723</invoicenumber>         <note/>         <numberofitems>9</numberofitems>     </invoiceinfo>     <sum>         <withouttax>90000</withouttax>         <tax>18900</tax>         <containingtaxtotal>108900</containingtaxtotal>     </sum>     <invoicelineitems>         <invoiceitem>             <itemnumber>1234</itemnumber>             <itemname>nokia sa</itemname>             <numberofunits>1</numberofunits>             <price>                 <perunit>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </perunit>                 <sum>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </sum>             </price>         </invoiceitem>         <invoiceitem>             <itemnumber>1234</itemnumber>             <itemname>nokia s</itemname>             <numberofunits>1</numberofunits>             <price>                 <perunit>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </perunit>                 <sum>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </sum>             </price>         </invoiceitem>         <invoiceitem>             <itemnumber>1235</itemnumber>             <itemname>nokia sb</itemname>             <numberofunits>1</numberofunits>             <price>                 <perunit>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </perunit>                 <sum>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </sum>             </price>         </invoiceitem>         <invoiceitem>             <itemnumber>1236</itemnumber>             <itemname>nokia sc</itemname>             <numberofunits>1</numberofunits>             <price>                 <perunit>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </perunit>                 <sum>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </sum>             </price>         </invoiceitem>         <invoiceitem>             <itemnumber>1231</itemnumber>             <itemname>nokia sr</itemname>             <numberofunits>1</numberofunits>             <price>                 <perunit>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </perunit>                 <sum>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </sum>             </price>         </invoiceitem>         <invoiceitem>             <itemnumber>1239</itemnumber>             <itemname>nokia sp</itemname>             <numberofunits>1</numberofunits>             <price>                 <perunit>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </perunit>                 <sum>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </sum>             </price>         </invoiceitem>         <invoiceitem>             <itemnumber>1277</itemnumber>             <itemname>nokia sx</itemname>             <numberofunits>1</numberofunits>             <price>                 <perunit>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </perunit>                 <sum>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </sum>             </price>         </invoiceitem>         <invoiceitem>             <itemnumber>1222</itemnumber>             <itemname>nokia sz</itemname>             <numberofunits>1</numberofunits>             <price>                 <perunit>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </perunit>                 <sum>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </sum>             </price>         </invoiceitem>         <invoiceitem>             <itemnumber>1111</itemnumber>             <itemname>nokia si</itemname>             <numberofunits>1</numberofunits>             <price>                 <perunit>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </perunit>                 <sum>                     <withouttax>10000</withouttax>                     <containingtax>12100</containingtax>                 </sum>             </price>         </invoiceitem>     </invoicelineitems> </invoice> 

xsl (to html)

<?xml version="1.0" encoding="utf-8"?> <ins:stylesheet version="2.0"     xmlns:ins="http://www.w3.org/1999/xsl/transform" xpath-default-namespace="http://josefdraslar.cz/" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xslformatting="urn:xslformatting">      <ins:output method="html" version="5.0" encoding="utf-8" indent="yes" />        <ins:template match="invoice">         <ins:result-document href="invoice.html">         <html>             <head>                 <title> <ins:value-of select="sellerparty/name/text()"/></title>                 <link rel="stylesheet" type="text/css" href="invoice.css"/>             </head>             <body>                 <div class="hlavni">                     <h1>faktura</h1>                      <ins:apply-templates/>                   </div>             </body>         </html>         </ins:result-document>     </ins:template>       <ins:template match="buyerparty">         <h2>kupující:</h2>         <p class="kupujici"><b>jméno: </b><ins:value-of select="name/text()"/><ins:text> </ins:text>             <ins:value-of select="surname/text()"/><br/>             <b>adresa: </b><ins:value-of select="/address1/street/text()"/>             <ins:text> </ins:text>             <ins:value-of select="address1/number/text()"/>             <ins:text>, </ins:text>             <ins:value-of select="address1/postalzone/text()"/>             <ins:text>, </ins:text>             <ins:value-of select="address1/city/text()"/> <br/>             <b>kontaktní údaje</b><br/>             <b>telefon: </b> <ins:value-of select="contact/fastcontact/telephone/text()"/><br/>             <b>email: </b> <ins:value-of select="contact/fastcontact/email/text()"/>    <br/>             </p>             </ins:template>      <ins:template match="sellerparty">         <h2>prodávající:</h2>         <p class="prodavajici"><b>jméno: </b><ins:value-of select="name/text()"/><br/>             <b>adresa: </b><ins:value-of select="address/street/text()"/>             <ins:text> </ins:text>             <ins:value-of select="address/number/text()"/>             <ins:text>, </ins:text>             <ins:value-of select="address/postalzone/text()"/>             <ins:text>, </ins:text>             <ins:value-of select="address/city/text()"/> <br/>             <b>kontaktní údaje</b><br/>             <b>telefon: </b> <ins:value-of select="contact/telephone/text()"/><br/>             <b>email: </b> <ins:value-of select="contact/email/text()"/>    <br/>             </p>             </ins:template>      <ins:template match="invoiceinfo">         <h2>obecné údaje:</h2>         <p class="faktura"><b>datum vydání: </b><ins:value-of select="issuedate/text()"/><br/>             <b>datum splatnosti: </b><ins:value-of select="maturity/text()"/> <br/>             <b>identifikační číslo: </b> <ins:value-of select="invoicenumber/text()"/><br/>             </p>     </ins:template>      <ins:template match="sum">         <h2>hodnota:</h2>         <p class="faktura">             <b>celková cena (bez dph): </b> <ins:value-of select="withouttax/text()"/><br/>             <b>celkové dph: </b> <ins:value-of select="tax/text()"/><br/>             <b>celková cena (s dph): </b> <ins:value-of select="containingtaxtotal/text()"/><br/>         </p>     </ins:template>      <ins:template match="invoicelineitems">         <h3>zboží:</h3>          <table>             <tr>                 <td>název</td>                 <td>počet kusů</td>                 <td>cena (s dph)</td>             </tr>             <ins:for-each select="invoiceitem">                 <ins:sort select="itemname"/>                 <ins:call-template name="akce"/>                 <tr>                     <td><a href="{position()}.html"><ins:value-of select="./itemname"/></a></td>                     <ins:choose>                         <ins:when test="itemnumber &gt; 1235">                             <td style="color: red;"><ins:value-of select="./itemnumber"/></td>                          </ins:when>                         <ins:otherwise>                             <td><ins:value-of select="./itemnumber"/></td>                         </ins:otherwise>                     </ins:choose>                      <td><ins:value-of select="./price/sum/containingtax"/></td>                 </tr>              </ins:for-each>             <tr>                 <td></td>                 <td>celkem</td>                 <td><ins:value-of select="../sum/containingtaxtotal/text()"/></td>             </tr>         </table>     </ins:template>      <ins:template name="akce">         <ins:result-document href="{position()}.html">             <html>                 <head>                     <title>zboží číslo <ins:value-of select="position()"/></title>                     <link rel="stylesheet" type="text/css" href="invoice.css"/>                 </head>                 <body>                     <div class="hlavni">                     <table>                         <tr>                             <td>název</td>                             <td>cena (bez dph)</td>                             <td>cena (s dph)</td>                         </tr>                              <tr>                                 <td><ins:value-of select="./itemname"/></td>                                 <td><ins:value-of select="./price/perunit/withouttax"/></td>                                 <td><ins:value-of select="./price/perunit/containingtax"/></td>                             </tr>                     </table>                         <p>                             <a href="invoice.html"><ins:text>zpět na hlavní stranu</ins:text></a>                         </p>                     </div>                 </body>             </html>                    </ins:result-document>     </ins:template>  </ins:stylesheet> 

to produce valid output html document need add exclude-result-prefixes="xsi xslformatting" on <ins:stylesheet> (root) element of stylesheet.

but indeed in stylesheet don't use xsi , xslformatting namespaces anywhere. modify stylesheet removing these namespaces declarations, leading :

<ins:stylesheet version="2.0"     xmlns:ins="http://www.w3.org/1999/xsl/transform" xpath-default-namespace="http://josefdraslar.cz/"> 

the namespace required bound "http://josefdraslar.cz/" uri, because default namespace of input xml, since declared xpath-default-namespace="http://josefdraslar.cz/", use namespace in xslt.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -