XSL和XPATH问题匹配(XSL and XPATH issue match)
我有这个XML文件:
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="cd.xsl"?> <produce> <item>apple<x>kk</x><y>jj</y></item> <item>banana<x>aaa</x></item> <item>pepper<x>qqq</x></item> </produce>
和这个XLS文件:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/"> <html> <body> <ul> <li><xsl:value-of select="node()"/></li> </ul> </body> </html> </xsl:template> </xsl:stylesheet>
我不明白“/”和“/ *”匹配之间的区别,因此我正在进行各种测试,例如上面的那些我得到了这个:
type="text/xsl" href="cd.xsl"
我不明白为什么。(我期待
produce
标签)。但是如果我使用这个XLS文件:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/*"> <html> <body> <ul> <li><xsl:value-of select="node()"/></li> </ul> </body> </html> </xsl:template> </xsl:stylesheet>
我得到空页(只有标签
li
的黑点)。 你能解释一下这些差异吗?I have this XML file:
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="cd.xsl"?> <produce> <item>apple<x>kk</x><y>jj</y></item> <item>banana<x>aaa</x></item> <item>pepper<x>qqq</x></item> </produce>
and this XLS file:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/"> <html> <body> <ul> <li><xsl:value-of select="node()"/></li> </ul> </body> </html> </xsl:template> </xsl:stylesheet>
I don't understand the difference between "/" and "/*" match and for this reason I'm doing various tests, for example like those above I get this:
type="text/xsl" href="cd.xsl"
and I don't understand why.(I expected
produce
tag).however if I use this XLS file:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/*"> <html> <body> <ul> <li><xsl:value-of select="node()"/></li> </ul> </body> </html> </xsl:template> </xsl:stylesheet>
I get empty page(only the black point of the tag
li
). Can you explain me those difference?
原文:https://stackoverflow.com/questions/34856580
最满意答案
只需在表达式中包含一个
floor()
-- ------------------------------------------------------------------- -- set-up some test data using a CTE: WITH tst as ( SELECT 13.7 finlength UNION ALL SELECT 123 ) -- alternatively: generate a table [tst] with a single column [finlength] -- ------------------------------------------------------------------- SELECT CONVERT(VARCHAR(20),FLOOR(finlength / 12)) + '''' + CONVERT(VARCHAR(20),finlength % 12)+'"' as FinishLen FROM tst -- results: FinishLen 1'1.70" 10'3."
这会将第一个(ft)值转换为整数,而第二个(in)仍将显示小数点后的所有数字。
UPDATE
当我从#tmp表中运行select时,我得到了与OP相同的错误。 我然后修改并最终得到这个:
它现在像地狱一样丑陋,但至少它现在有效 ,请参见此处SQL演示 :
create table #tst (finlength float); INSERT INTO #tst VALUES (13.7),(123.),(300.9); SELECT CONVERT(VARCHAR(20),FLOOR(finlength / 12)) + '''' -- ft +CONVERT(VARCHAR(20),finlength-FLOOR(finlength) -- in: fractional part +CAST(FLOOR(finlength) as int) %12)+'"' -- in: integer part as FinishLen FROM #tst
请注意:公式将返回正值的合理结果。 对于“负距离”,需要进一步改变。 如果在不同的地方需要类似的输出,那么UDF在这里是有意义的。 就像是:
CREATE FUNCTION ftinstr(@v float) RETURNS varchar(32) BEGIN DECLARE @l int; SELECT @l=FLOOR(ABS(@v)); RETURN CAST(SIGN(@v)*(@l/12) AS varchar(6))+'''' +CAST( ABS(@v)-@l+@l%12 AS varchar(20))+'"' END
会做的伎俩,被称为
dbo.ftinstr( floatval )
。也许我还能把它美化一下......
Just include a
floor()
in your expression like-- ------------------------------------------------------------------- -- set-up some test data using a CTE: WITH tst as ( SELECT 13.7 finlength UNION ALL SELECT 123 ) -- alternatively: generate a table [tst] with a single column [finlength] -- ------------------------------------------------------------------- SELECT CONVERT(VARCHAR(20),FLOOR(finlength / 12)) + '''' + CONVERT(VARCHAR(20),finlength % 12)+'"' as FinishLen FROM tst -- results: FinishLen 1'1.70" 10'3."
This will turn the first (ft) value into an integer while the second one (in) will still show all the digits after the decimal point.
UPDATE
When I ran the select from a #tmp table I got the same error as OP. I then modified and ended up with this:
It is as ugly as hell now, but at least it works now, see here SQL Demo:
create table #tst (finlength float); INSERT INTO #tst VALUES (13.7),(123.),(300.9); SELECT CONVERT(VARCHAR(20),FLOOR(finlength / 12)) + '''' -- ft +CONVERT(VARCHAR(20),finlength-FLOOR(finlength) -- in: fractional part +CAST(FLOOR(finlength) as int) %12)+'"' -- in: integer part as FinishLen FROM #tst
Please note: The formula will return reasonable results for positive values. For "negative distances" further changes are necessary. If similar output is required in different places then a UDF makes sense here. Something like:
CREATE FUNCTION ftinstr(@v float) RETURNS varchar(32) BEGIN DECLARE @l int; SELECT @l=FLOOR(ABS(@v)); RETURN CAST(SIGN(@v)*(@l/12) AS varchar(6))+'''' +CAST( ABS(@v)-@l+@l%12 AS varchar(20))+'"' END
would do the trick, To be called like
dbo.ftinstr( floatval )
.Maybe I can beautify it a little still ...
相关问答
更多-
FT232RL上的流量控制(Flow control on a FT232RL)[2022-03-29]
TL; DR 根据FTDI文档 ,引脚CBUS2的默认配置是TXDEN ,它专为此功能而设计,因此只需使用引脚CBUS2即可实现收发器使能。 背景 FTDI芯片当然能够进行DTR / DSR流量控制 。 但这是因为硬件本身处理流量控制(与远端通信,可以提供背压)。 无需软件参与。 使用像RS485这样的多点总线,实际的流量控制在软件中处理,硬件只在软件指示时发送数据。 正如您的一位评论者建议的那样,您可以编写其他软件来打开DTR,发送数据并关闭DTR。 但这对于满足严格的时序是有问题的,并且没有实际需要,因 ... -
只需在表达式中包含一个floor() -- ------------------------------------------------------------------- -- set-up some test data using a CTE: WITH tst as ( SELECT 13.7 finlength UNION ALL SELECT 123 ) -- alternatively: generate a table [tst] with a single column [finlen ...
-
再看一下, 将转换C#double的答案发布到Delphi Real48的方法很清楚。 备查: /** * Convert a PHP number [Int|Float] to a Turbo Pascal 48-bit (6 byte) real byte representation * @param float number to convert * @return binary 48-bit real */ function doubleToReal48($double) { $b ...
-
假设这些单元总是出现在字符串的末尾,你可以尝试一个合适的子字符串,例如 DECLARE @mass VARCHAR(50); SET @mass = '0.600 KG'; SELECT CAST(SUBSTRING(@mass, 1, CHARINDEX(' ', @mass) - 1) AS real); 当然,单位的概念将会丢失,而你只会有一个真实的数字。 演示 Assuming the units always appear at the end of the string, you could ...
-
无法在sql中格式化实数(Cannot format real number in sql)[2023-02-15]
假设你试图去除小数点后面的零(如果没有其他结尾数字,小数点),但确保你总是有一个整数(因此0.06不是格式化为.06 )。 您的查询: select TRIM( rtrim( to_char( 10.00, '999990.9999999' ), '9999999999999990' || rpad( '.', 8 + 1, '0' ) ) ) from dual; 因为rpad( '.', 8 + 1, '0' ... -
一班VBA: Function ConvertFtInches(pInput As String) As Double ConvertFtInches = Split(pInput, " ft ")(0) + Split(Split(pInput, " ft ")(1), " in")(0) / 12 End Function One liner VBA: Function ConvertFtInches(pInput As String) As Double ConvertFtInches = Spli ...
-
FreeType2 FT_Outline_Decompose返回大量数字(FreeType2 FT_Outline_Decompose returns huge numbers)[2023-05-22]
set funcs.shift = 0; funcs.delta = 0; 将工作 set funcs.shift = 0; funcs.delta = 0; will work -
这应该工作: plt.hist(data.astype(float)) This should work: plt.hist(data.astype(float))
-
如果您尝试使用此代码: ft232h.setup(9,GPIO.OUT) ft232h.setup(10,GPIO.OUT) ft232h.output(9, GPIO.HIGH) ft232h.output(10, GPIO.HIGH) 你有两个针高吗? 并使用以下代码? ft232h.setup(9,GPIO.OUT) ft232h.output(9, GPIO.HIGH) ft232h.setup(10,GPIO.OUT) ft232h.output(10, GPIO.HIGH) If you t ...
-
有多种方式。 我将使用f而不是下面的浮点数。 如果你对下一个最高整数感兴趣, (ceiling f)给你这个。 如果你对下一个最小的整数感兴趣, (floor f)给你(对于像1.0这样的值,这两个函数将返回相同的整数值)。 如果您希望使用最接近的整数,则可以使用(round f)来查找它。 这些是我能想到的三种最简单,最便携的方式。 There are multiple ways. I will be using f instead of a float number below. If you're i ...