次の質問に対する答えを見つけるのに苦労していますが、これはかなり一般的なように思われるので、基本的な何かが欠けているに違いありません。手伝ってくれませんか。
考案されたXMLスキーマ、サンプルXML入力、およびXMLをHTMLに変換するために使用される以下のサンプルXSLTを前提としています。タグ内に属性を設定するにはどうすればよいですか?たとえば、、<div id=HouseNumber>
など<input type="checkbox" id=Zipcode>
?
注: HouseNumberとZipcodeの前後に引用符がないのは、当然のことです。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タグには家番号のIDがあります。
<div class="houseStyle" id="123">
<ul>
<li>California</li>
<li>Los Angeles County</li>
<li>Los Angeles</li>
<li>90210</li>
</ul>
</div>