ฉันมีช่วงเวลาที่ยากลำบากในการหาคำตอบสำหรับคำถามต่อไปนี้ ซึ่งดูเหมือนจะเป็นเรื่องธรรมดา ดังนั้นฉันจึงขาดสิ่งพื้นฐานบางอย่างไป คุณช่วยฉันหน่อยได้ไหม?
ด้วยสคีมา XML ที่วางแผนไว้ อินพุต XML ตัวอย่าง และ XSLT ตัวอย่างด้านล่างที่ใช้ในการแปลง XML เป็น HTML ฉันจะตั้งค่าคุณสมบัติภายในแท็กได้อย่างไร เช่น <div id=HouseNumber>
,<input type="checkbox" id=Zipcode>
ฯลฯ?
หมายเหตุ: การไม่มีเครื่องหมายคำพูดรอบ HouseNumber และรหัสไปรษณีย์นั้นมีจุดประสงค์ ฉันกำลังพยายามใส่ค่าของคุณลักษณะเหล่านี้จากอินพุต XML ลงใน id="", for="", name="" ฯลฯ
ขอขอบคุณที่สละเวลาและป้อนข้อมูลเกี่ยวกับคำถามเวอร์ชันแรก
bn
ตัวอย่างสคีมา XML
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Location">
<xs:complexType>
<xs:attribute name="State" type="xs:string" use="required" />
<xs:attribute name="County" type="xs:string" use="required" />
<xs:attribute name="City" type="xs:string" use="required" />
<xs:attribute name="Zipcode" type="xs:nonNegativeInteger" use="required" />
<xs:attribute name="HouseNumber" type="xs:nonNegativeInteger" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>
ตัวอย่างอินพุต XML:
<Location>
<State>California</State>
<County>Los Angeles County</County>
<City>Los Angeles</City>
<Zipcode>90210</Zipcode>
<HouseNumber>123</HouseNumber>
</Location>
ตัวอย่าง XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:for-each select="Location">
<!--Inner HTML example, div has no id-->
<div class="houseStyle">
<ul>
<li><xsl:value-of select="Location/State"/></li>
<li><xsl:value-of select="Location/County"/></li>
<li><xsl:value-of select="Location/City"/></li>
<li><xsl:value-of select="Location/Zipcode"/></li>
</ul>
</div>
<!--Inner HTML example again, but how do I
set the div id to HouseNumber?-->
<div class="houseStyle" id=HouseNumber>
<ul>
<li><xsl:value-of select="Location/State"/></li>
<li><xsl:value-of select="Location/County"/></li>
<li><xsl:value-of select="Location/City"/></li>
<li><xsl:value-of select="Location/Zipcode"/></li>
</ul>
</div>
</xsl:for-each>
</xsl:stylesheet>
เอาต์พุต HTML ที่ต้องการ โดยที่แท็ก div มีรหัสของบ้านเลขที่:
<div class="houseStyle" id="123">
<ul>
<li>California</li>
<li>Los Angeles County</li>
<li>Los Angeles</li>
<li>90210</li>
</ul>
</div>