我試圖將XML轉換爲看起來像另一個XML的輸出。但我不確定如何打印「正斜槓」。 我需要輸出也有標籤。 這是我必須轉換嘗試將XML文件轉換爲不同的xml文件
<ItemDetails>
<Item>
<Code>3390876231</Code>
<Customer id='1055'>
<FirstName>John</FirstName>
<MiddleName>M</MiddleName>
<LastName>Crusoe</LastName>
<Title>Mr.</Title>
<Address>
<HouseNumber>House11</HouseNumber>
<Street>St.Marks Street</Street>
<Country>UK</Country>
<ContactNumber>
<PhoneNumber1>0657385245</PhoneNumber1>
<PhoneNumber2>0657385211</PhoneNumber2>
</ContactNumber>
<PostalCode>3452DD</PostalCode>
</Address>
</Customer>
<Name>Romeo and Juliet</Name>
<Type>compact disc</Type>
<Author>Rostropovich</Author>
<ListPrice>18.98</ListPrice>
<SellPrice>13.99</SellPrice>
<Cost>9.92</Cost>
</Item>
<Item>
<Code>3390007231</Code>
<Customer id='1056'>
<FirstName>Kayne</FirstName>
<MiddleName/>
<LastName>West</LastName>
<Title>Mr.</Title>
<Address>
<HouseNumber>House78</HouseNumber>
<Street>Pittsburg Street</Street>
<Country>USA</Country>
<ContactNumber>
<PhoneNumber1>0690885245</PhoneNumber1>
<PhoneNumber2>0690785211</PhoneNumber2>
</ContactNumber>
<PostalCode>3882PP</PostalCode>
</Address>
</Customer>
<Name>XSLT</Name>
<Type>book</Type>
<Author>Tidwell</Author>
<ListPrice>49.95</ListPrice>
<SellPrice>34.99</SellPrice>
<Cost>22.92</Cost>
</Item>
<Item>
<Code>3390876001</Code>
<Customer id='1057'>
<FirstName>Martha</FirstName>
<MiddleName>W</MiddleName>
<LastName>Hamilton</LastName>
<Title>Mrs.</Title>
<Address>
<HouseNumber>House456</HouseNumber>
<Street>Alfred Street</Street>
<Country>UK</Country>
<ContactNumber>
<PhoneNumber1>0659985245</PhoneNumber1>
<PhoneNumber2>0657300011</PhoneNumber2>
</ContactNumber>
<PostalCode>3786CD</PostalCode>
</Address>
</Customer>
<Name>The Little Schemer</Name>
<Type>book</Type>
<Author>Friedman</Author>
<Author>Felleisen</Author>
<ListPrice>29.95</ListPrice>
<SellPrice>26.99</SellPrice>
<Cost>17.92</Cost>
</Item>
<Item>
<Code>3399996231</Code>
<Customer id='1058'>
<FirstName>Harold</FirstName>
<MiddleName/>
<LastName>Crossley</LastName>
<Title>Mr.</Title>
<Address>
<HouseNumber>House909</HouseNumber>
<Street>Beaumont Street</Street>
<Country>UK</Country>
<ContactNumber>
<PhoneNumber1>0656665245</PhoneNumber1>
<PhoneNumber2>0657385200</PhoneNumber2>
</ContactNumber>
<PostalCode>3772DI</PostalCode>
</Address>
</Customer>
<Name>A Tribute to People’s Princess: Diana</Name>
<Type>book</Type>
<Author>Peter Donelli</Author>
<ListPrice>65.98</ListPrice>
<SellPrice>78.99</SellPrice>
<Cost>60.92</Cost>
</Item>
<Item>
<Code>33908755118</Code>
<Customer id='1059'>
<FirstName>Donna</FirstName>
<MiddleName>H</MiddleName>
<LastName>Miller</LastName>
<Title>Miss</Title>
<Address>
<HouseNumber>House998</HouseNumber>
<Street>Maple Street</Street>
<Country>USA</Country>
<ContactNumber>
<PhoneNumber1>8002255288</PhoneNumber1>
<PhoneNumber2>8011155288</PhoneNumber2>
</ContactNumber>
<PostalCode>3662DD</PostalCode>
</Address>
</Customer>
<Name>KingMozart</Name>
<Type>compact disc</Type>
<Author>Donald Runnicles</Author>
<ListPrice>20.98</ListPrice>
<SellPrice>18.99</SellPrice>
<Cost>22.92</Cost>
</Item>
</ItemDetails>
這是輸出應該如何將XML文件。要嵌套的標籤被刪除並按順序同步。
<ItemDetails>
<Item>
<Code>3390876231</Code>
<CustomerID>1055</CustomerID>
<FullName>Mr.John M Crusoe</FullName>
<Address>House11,St.Marks Street,UK</Address>
<ContactNumbers>0657385245,0657385211</ContactNumbers>
<PostalCode>3452DD</PostalCode>
<ItemName>Romeo and Juliet</ItemName>
<ItemType>compact disc</ItemType>
<Author>Rostropovich</Author>
<list-price>18.98</list-price>
<sell-price>13.99</sell-price>
<cost-price>9.92</cost-price>
<profit>4.07</profit>
</Item>
<Item>
<Code>3390007231</Code>
<CustomerID>1056</CustomerID>
<FullName>Mr.Kayne West</FullName>
<Address>House78,Pittsburg Street,USA</Address>
<ContactNumbers>0690885245</ContactNumbers>
<PostalCode>3882PP</PostalCode>
<ItemName>XSLT</ItemName>
<ItemType>book</ItemType>
<Author>Tidwell</Author>
<list-price>49.95</list-price>
<sell-price>34.99</sell-price>
<cost-price>22.92</cost-price>
<profit>12.07</profit>
</Item>
</ItemDetails>
這是我的代碼。我不知道如何將標籤輸出
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<html>
<body>
<xsl:for-each select="Item">
\t <p><Code><xsl:value-of select="Code"/></Code></br>
\t <CustomerID><xsl:value-of select="Customer"/></CustomerID></br>
\t <xsl:for-each select="Customer">
\t <CustomerID><xsl:value-of select="Customer/@id"/></CustomerID></br>
\t <FullName><xsl:value-of select="Title"/> <xsl:value-of select="FirstName"/> <xsl:value-of select="MiddleName"/> <xsl:value-of select="LastName"/></FullName> </br>
\t <Address>
\t <xsl:for-each select="Address">
\t <xsl:value-of select="HouseNumber"/> <xsl:value-of select="Street"/> <xsl:value-of select="Country"/> </Address> </br>
\t <ContactNumbers><xsl:for-each select="ContactNumber"> <xsl:value-of select="PhoneNumber1"/> , <xsl:value-of select="PhoneNumber2"/> </xsl:for-each></ContactNumbers> </br>
\t <PostalCode><xsl:value-of select="PostalCode"/></PostalCode></br>
\t </xsl:for-each>
\t </xsl:for-each>
\t <ItemName><xsl:value-of select="Name"/></ItemName></br>
\t <ItemType><xsl:value-of select="Type"/></ItemType></br>
\t <Author><xsl:value-of select="Author"/></Author></br>
\t <list-price><xsl:value-of select="ListPrice"/></list-price></br>
\t <sell-price><xsl:value-of select="SellPrice"/><sell-price></br>
\t <cost-price><xsl:value-of select="Cost"/></cost-price></br></p>
\t </xsl:for-each>
</body>
</html>
</xsl:stylesheet>
\t \t
您已將所需輸出顯示爲XML,但您嘗試使用的XSLT包含'html'。你需要XML還是HTML作爲輸出? –
@AniketV我希望XSLT的輸出看起來像xml。 –
那麼您發佈的XSLT代碼究竟與您的問題有什麼關係?你只是發佈任何代碼? – Tomalak