Friday, 15 August 2014

html - XML and XSL format linking -


Hi, I'm having trouble connecting my XML and XSLT, my XML is long but a quote, The problem is that I do not have XSLT formatting it, I am trying to display my XML with one title below each other, I'm sorry but English is not my first language

XML: < / P>

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt ;? Xml-stylesheet type = "text / xsl" href = "product_list.xsl"? & Gt; & Lt; ProductCatalogue & gt; & Lt; Beverage & gt; & Lt; Products & gt; & Lt; Name Product_Code = "D001" & gt; Limbons & lt; / Name & gt; & Lt; Price & gt; 6.50 & lt; / Pricing & gt; & Lt; Amount & gt; 20 & lt; / Zodiac & gt; & Lt; Supplier & gt; Coca Cola & lt; / Supplier & gt; & Lt; / Products & gt; & Lt; / Drink & gt; & Lt; / ProductCatalogue & gt;  

XSLT

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Xsl: stylesheet version = "1.0" xmlns: xsl = "http://www.w3.org/1999/XSL/transform" & gt; & Lt; Xsl: template match = "/" & gt; & Lt; Html & gt; & Lt; Body & gt; & Lt; H3 & gt; Product List & lt; / H3 & gt; & Lt; XSL: implemented-templates / & gt; & Lt; / Body & gt; & Lt; / Html & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: Template Match = "Drink" & gt; & Lt; Div style = "color: # 0000ff" & gt; & Lt; H3 & gt; & Lt; Xsl: Select the value = "name" /> & Lt; / H3 & gt; & Lt; / Div & gt; & Lt; Div & gt; & Lt; Xsl: Select Value = "Name @ ProductCode" /> & Lt; / Div & gt; & Lt; P & gt; Price: & lt; Xsl: Select Value = "Price" /> & Lt; / P & gt; & Lt; P & gt; Supplier: & lt; Xsl: Select Value = "Supplier" /> & Lt; / P & gt; & Lt; P & gt; Amount: & lt; Xsl: Select the value = "zodiac" /> & Lt; / P & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt;  

I believe this is a problem with my templates But I'm not sure how this fixed

Yes, there really is a problem with your template. Basically

  & lt; Xsl: template match = "drinks" & gt; The easiest way to produce your conversion is to change the second template match.  

to

  & lt; Xsl: template match = "product" & gt;  

Within this template, you are selecting elements such as name and value , which are the product Children have elements>, not drinks .

In addition,

  & lt; Xsl: Select value = "name @ product code" />  

to

  & lt; Xsl: Select Value = "Name / @ ProductCode" />  

XML and its related technologies are case-sensitive - Product_code are not equal Product_Code .

Then, the output will be

  & lt; Html & gt; & Lt; Body & gt; & Lt; H3 & gt; Product List & lt; / H3 & gt; & Lt; Div style = "color: # 0000ff" & gt; & Lt; H3 & gt; Lemonade & lt; / H3 & gt; & Lt; / Div & gt; & Lt; Div & gt; D001 & lt; / Div & gt; & Lt; P & gt; Price: 6.50 & lt; / P & gt; & Lt; P & gt; Supplier: Coca-Cola & lt; / P & gt; & Lt; P & gt; Amount: 20 & lt; / P & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

No comments:

Post a Comment