xml - xsl 列大小和对齐方式
问题描述
我有这个 xsl 文件和 xml 文件 - 正如您在屏幕截图中看到的 _ 无法将县和市的列标题与 ID、州、首都放在同一表的第一行。鉴于县是州的子级,而城市是县的子级,我将其放在模板中。但我无法将列标题与字段对齐。此外,我无法像父列一样修复子元素的列大小。我尝试使用宽度和 colspan,但没有任何变化。谢谢你的帮助。
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
<html>
<head>
<title>Books</title>
</head>
<body>
<table width="100%" border="1">
<THEAD>
<TR>
<TD width="5%" style="white-space: nowrap; text-overflow:ellipsis; overflow: hidden; max-width:1px;">
<B>ID</B>
</TD>
<TD width="10%">
<B>State</B>
</TD>
<TD width="15%">
<B>Capital</B>
</TD>
<TD width="10%">
<B>CountyName</B>
</TD>
<TD width="10%">
<B>CountyName</B>
</TD>
<TD width="10%">
<B>CityName</B>
</TD>
<TD width="10%">
<B>CityArea</B>
</TD>
</TR>
</THEAD>
<TBODY>
<xsl:for-each select="geo_DB/geo_db/state">
<TR>
<TD width="200px" style="white-space: nowrap; text-overflow:ellipsis; overflow: hidden; max-width:1px;">
<xsl:value-of select="@id" />
</TD>
<TD width="30px">
<xsl:value-of select="stateName" />
</TD>
<TD width="15%">
<xsl:value-of select="stateCapital" />
</TD>
<TD width="70%">
<xsl:apply-templates select="county" />
</TD>
</TR>
</xsl:for-each>
</TBODY>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="county">
<table border="1">
<!--thead>
<TR>
<TD width="15%">
<B>Name</B>
</TD>
<TD width="10%">
<B>Area</B>
</TD>
<TD width="65%">
<B>Cities</B>
</TD>
</TR>
</thead-->
<TBODY>
<TR>
<TD width="25%">
<xsl:value-of select="countyName" />
</TD>
<TD width="10%">
<xsl:value-of select="countyArea" />
</TD>
<TD colspan="4" width="65%">
<xsl:apply-templates select="city" />
</TD>
</TR>
</TBODY>
</table>
</xsl:template>
<xsl:template match="city">
<table border="1">
<TBODY>
<TR>
<TD width="35%">
<xsl:value-of select="cityName" />
</TD>
<TD width="40%">
<xsl:value-of select="cityPopulation" />
</TD>
</TR>
</TBODY>
</table>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="multiTER.xsl"?>
<geo_DB xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="XMLFIle.xsd">
<!-- Geo database-->
<geo_db>
<!-- This is a state-->
<state id = "state1">
<stateName>Missouri</stateName>
<stateCapital>Jefferson</stateCapital>
<!-- This is a country-->
<county>
<countyName>Jackson</countyName>
<countyArea>4.2</countyArea>
<countyLocation>
<countyLatitude>52.3</countyLatitude>
<countyLongitude>53.3</countyLongitude>
</countyLocation>
<!-- This is a city-->
<city>
<cityName>Kansas</cityName>
<cityPopulation>45</cityPopulation>
<cityLocation>
<cityLatitude>52.31</cityLatitude>
<cityLongitude>53.31</cityLongitude>
</cityLocation>
</city>
<!-- This is another city-->
<city>
<cityName>City in Jackson</cityName>
<cityPopulation>55</cityPopulation>
<cityLocation>
<cityLatitude>52.32</cityLatitude>
<cityLongitude>53.32</cityLongitude>
</cityLocation>
</city>
</county>
<!-- This is another country-->
<county>
<countyName>Greene</countyName>
<countyArea>2</countyArea>
<countyLocation>
<countyLatitude>52.8</countyLatitude>
<countyLongitude>53.8</countyLongitude>
</countyLocation>
<city>
<cityName>temp</cityName>
<cityPopulation>4578</cityPopulation>
<cityLocation>
<cityLatitude>10.8</cityLatitude>
<cityLongitude>25.9</cityLongitude>
</cityLocation>
</city>
</county>
</state>
<!-- This is another state-->
<state id="state2">
<stateName>Ontario</stateName>
<stateCapital>Toronto</stateCapital>
<county>
<countyName>Frontenac</countyName>
<countyArea>3787</countyArea>
<countyLocation>
<countyLatitude>23.8</countyLatitude>
<countyLongitude>12.9</countyLongitude>
</countyLocation>
<city>
<cityName>Kingston</cityName>
<cityPopulation>123787</cityPopulation>
<cityLocation>
<cityLatitude>45.4</cityLatitude>
<cityLongitude>23.1</cityLongitude>
</cityLocation>
</city>
</county>
</state>
<state id="state3">
<stateName>Alabama</stateName>
<stateCapital>Montgomery</stateCapital>
<county>
<countyName>Autaaga</countyName>
<countyArea>1212</countyArea>
<countyLocation>
<countyLatitude>23.8</countyLatitude>
<countyLongitude>12.9</countyLongitude>
</countyLocation>
<city>
<cityName>Millbrock</cityName>
<cityPopulation>412</cityPopulation>
<cityLocation>
<cityLatitude>49.4</cityLatitude>
<cityLongitude>29.1</cityLongitude>
</cityLocation>
</city>
</county>
<county>
<countyName>Baldwin </countyName>
<countyArea>43344</countyArea>
<countyLocation>
<countyLatitude>49.8</countyLatitude>
<countyLongitude>29.9</countyLongitude>
</countyLocation>
<city>
<cityName>Bay Minette</cityName>
<cityPopulation>7856</cityPopulation>
<cityLocation>
<cityLatitude>49.4</cityLatitude>
<cityLongitude>29.1</cityLongitude>
</cityLocation>
</city>
</county>
<county>
<countyName>Barbour </countyName>
<countyArea>777</countyArea>
<countyLocation>
<countyLatitude>23.8</countyLatitude>
<countyLongitude>12.9</countyLongitude>
</countyLocation>
<city>
<cityName>Cilo</cityName>
<cityPopulation>7856</cityPopulation>
<cityLocation>
<cityLatitude>49.4</cityLatitude>
<cityLongitude>29.1</cityLongitude>
</cityLocation>
</city>
<city>
<cityName>Eufaula</cityName>
<cityPopulation>44</cityPopulation>
<cityLocation>
<cityLatitude>49.4</cityLatitude>
<cityLongitude>29.1</cityLongitude>
</cityLocation>
</city>
</county>
</state>
<state id="state4">
<stateName>Arizona</stateName>
<stateCapital>Phoenix</stateCapital>
<county>
<countyName>Apache</countyName>
<countyArea>1212</countyArea>
<countyLocation>
<countyLatitude>23.8</countyLatitude>
<countyLongitude>12.9</countyLongitude>
</countyLocation>
<city>
<cityName>St-John</cityName>
<cityPopulation>412</cityPopulation>
<cityLocation>
<cityLatitude>49.4</cityLatitude>
<cityLongitude>29.1</cityLongitude>
</cityLocation>
</city>
</county>
<county>
<countyName>Cochise </countyName>
<countyArea>43344</countyArea>
<countyLocation>
<countyLatitude>49.8</countyLatitude>
<countyLongitude>29.9</countyLongitude>
</countyLocation>
<city>
<cityName>Benson</cityName>
<cityPopulation>7856</cityPopulation>
<cityLocation>
<cityLatitude>49.4</cityLatitude>
<cityLongitude>29.1</cityLongitude>
</cityLocation>
</city>
</county>
<county>
<countyName>Coconino </countyName>
<countyArea>777</countyArea>
<countyLocation>
<countyLatitude>23.8</countyLatitude>
<countyLongitude>12.9</countyLongitude>
</countyLocation>
<city>
<cityName>Flagstaff</cityName>
<cityPopulation>7856</cityPopulation>
<cityLocation>
<cityLatitude>49.4</cityLatitude>
<cityLongitude>29.1</cityLongitude>
</cityLocation>
</city>
<city>
<cityName>Page</cityName>
<cityPopulation>44</cityPopulation>
<cityLocation>
<cityLatitude>49.4</cityLatitude>
<cityLongitude>29.1</cityLongitude>
</cityLocation>
</city>
</county>
</state>
<state id = "state5">
<stateName>Colorado</stateName>
<stateCapital>Denver</stateCapital>
<!-- This is a country-->
<county>
<countyName>Adams</countyName>
<countyArea>4.2</countyArea>
<countyLocation>
<countyLatitude>52.3</countyLatitude>
<countyLongitude>53.3</countyLongitude>
</countyLocation>
<!-- This is a city-->
<city>
<cityName>Arvada</cityName>
<cityPopulation>45</cityPopulation>
<cityLocation>
<cityLatitude>52.31</cityLatitude>
<cityLongitude>53.31</cityLongitude>
</cityLocation>
</city>
<!-- This is another city-->
<city>
<cityName>Aurora</cityName>
<cityPopulation>578525</cityPopulation>
<cityLocation>
<cityLatitude>52.32</cityLatitude>
<cityLongitude>53.32</cityLongitude>
</cityLocation>
</city>
</county>
<!-- This is another country-->
<county>
<countyName>Crowley</countyName>
<countyArea>2</countyArea>
<countyLocation>
<countyLatitude>52.8</countyLatitude>
<countyLongitude>53.8</countyLongitude>
</countyLocation>
<city>
<cityName>Olney</cityName>
<cityPopulation>64445</cityPopulation>
<cityLocation>
<cityLatitude>10.8</cityLatitude>
<cityLongitude>25.9</cityLongitude>
</cityLocation>
</city>
</county>
</state>
<state id = "state6">
<stateName>Connecticut</stateName>
<stateCapital>Hartford</stateCapital>
<!-- This is country-->
<county>
<countyName>Fairfield</countyName>
<countyArea>2</countyArea>
<countyLocation>
<countyLatitude>52.8</countyLatitude>
<countyLongitude>53.8</countyLongitude>
</countyLocation>
<city>
<cityName>Stamford</cityName>
<cityPopulation>45466</cityPopulation>
<cityLocation>
<cityLatitude>10.8</cityLatitude>
<cityLongitude>25.9</cityLongitude>
</cityLocation>
</city>
</county>
</state>
</geo_db>
</geo_DB>
解决方案
推荐阅读
- java - 用户登录桌面应用程序时如何隐藏登录/注册表单?
- java - 如果变量的值在过去 24 小时内没有改变
- junit5 - JUnit 从数据库中检索值以测试标准
- dart - 缺少 Dart 空值检查速记?
- python - 在续行中混合普通字符串和 f 字符串
- python - 从另一个数据帧中分配一个数字 - Series([], Name: id, dtype: float64)
- c# - 通过按钮启用和禁用文本框?(asp.net)
- c# - Selenium - 检查元素不存在的等待时间太长
- java - 为什么 getAllTrackables 方法只返回一张脸?
- python - 如何在python中从网络摄像头视频20秒后开始捕获视频帧