我正在阅读一本名为ineasysteps的书,我仍然坚持关于XSL和XML的一个问题。
出于某种原因,我无法在浏览器中打开xml文档。我相信我的代码不正确,但请让我知道我在这里做错了什么。
谢谢,代码发布如下:
这是XML Document:cars.xml
<?xml version = "1.0" encoding = "UTF-8" ?>
<!-- XML in easy steps - Page 99. -->
<?xml-stylesheet type = "text/xsl" href = "value-of.xsl" ?>
<car:doc
xmlns:xsi =
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation =
"http://www.ineasysteps.com/xsd cars.xsd"
xmlns:car = "http://www.ineasysteps.com/xsd" >
<car:item id = "corvette">
<car:make>Chevrolet</car:make>
<car:model>Corvette</car:model>
<car:ltr>6.0</car:ltr>
<car:cyl>8</car:cyl>
<car:hp>400</car:hp>
<car:price>53000</car:price>
</car:item>
<car:item id = "viper">
<car:make>Dodge</car:make>
<car:model>Viper</car:model>
<car:ltr>8.3</car:ltr>
<car:cyl>10</car:cyl>
<car:hp>510</car:hp>
<car:price>85000</car:price>
</car:item>
<car:item id = "solstice">
<car:make>Pontiac</car:make>
<car:model>Solstice</car:model>
<car:ltr>2.4</car:ltr>
<car:cyl>4</car:cyl>
<car:hp>177</car:hp>
<car:price>22000</car:price>
</car:item>
这是value-of.xsl文档:
<?xml version = "1.0" encoding = "UTF-8" ?>
<!-- XML in easy steps - Page 100. -->
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns:c = "http://www.ineasysteps.com/xsd" >
<xsl:output method="html" encoding="UTF-8" indent="yes"/>
<xsl:template match = "/">
<html> <head><title>XSL Output</title> </head> <body>
<ul style = "list-style-type:square;color:red">
<li> <xsl:value-of select = "car:item/car:make" /> </li>
<li> <xsl:value-of select = "car:item/car:model" /> </li>
<li> <xsl:value-of select = "car:item/car:ltr" /> Liters </li>
<li> <xsl:value-of select = "car:item/car:cyl" /> Cylinders</li>
<li> <xsl:value-of select = "car:item/car:hp" /> Horsepower</li>
<li> <xsl:value-of select = "car:item/car:price" /> </li>
</ul>
</body> </html>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:0)
考虑为EVB <- function(x) {
ind <- x[["Z"]]==0
Mx <- max(x[["Attrition"]][ind], na.rm = TRUE);
ind <- x[["Z"]]==1
Mn <- min(x[["Attrition"]][ind], na.rm = TRUE);
list(Mn, Mx) ## or return(list(Mn, Mx))
}
EVB(df)
级别使用第二个模板,然后使用car:doc
级别。另外,使用exclude-prefixes删除根car:item
标记中的名称空间:
<html>
转换输出
<?xml version = "1.0" encoding = "UTF-8" ?>
<!-- XML in easy steps - Page 100. -->
<xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns:car = "http://www.ineasysteps.com/xsd"
exclude-result-prefixes="xsl car">
<xsl:output method="html" encoding="UTF-8" indent="yes"/>
<!-- ROOT LEVEL -->
<xsl:template match="car:doc">
<html>
<head><title>XSL Output</title></head>
<body>
<xsl:apply-templates select="car:item"/>
</body>
</html>
</xsl:template>
<!-- FIRST CHILD LEVEL -->
<xsl:template match="car:item">
<ul style = "list-style-type:square;color:red">
<li> <xsl:value-of select = "car:make" /> </li>
<li> <xsl:value-of select = "car:model" /> </li>
<li> <xsl:value-of select = "car:ltr" /> Liters </li>
<li> <xsl:value-of select = "car:cyl" /> Cylinders</li>
<li> <xsl:value-of select = "car:hp" /> Horsepower</li>
<li> <xsl:value-of select = "car:price" /> </li>
</ul>
</xsl:template>
</xsl:stylesheet>