另一个XSLT问题 [英] another XSLT problem

查看:70
本文介绍了另一个XSLT问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在尝试解决XSLT问题,我希望有人可以提供一个

的小指导。我正在将XML转换为HTML。


这里是我正在处理的XML文件的一个例子,大大简化了:


-----------------

< root>


< object name =" a" ;>

< item name =" a1"> Text here< / item>

< item name =" readonlya2"> Text here< / item>

< item name =" a3"> Text here< / item>

< item name =" readonlya4"> Text here< / item>

< item name =" a5"> Text here< / item>

< / object>


< object name =" b">

< item name =" b1"> Text here< / item>

< item name =" b2"> Text here< / item>

< item name =" b3"> Text here< / item>

< item name =" b4"> Text here< / item>

< item name =" b5"> Text here< / item>

< / object>


< / root>

-------------- --------


一个< object> element包含多个< item>元素。我处理每个

< object>另外。


如果< object>不包含只读< item>元素(由

name =" readonly .."标识),我想打印无。在HTML输出中。


如果有一个或多个只读< item>在< object>中,我将显示

那些只读< item> HTML表格中的元素。


看起来很简单,但我尝试过使用一个密钥,一个递归的

模板,以及我能想到的任何其他内容。在将某些内容放入结果树之前,我无法确定

是否为任何只读< item>。

如果我可以设置全局变量从模板中,然后它将很容易检查该变量,以判断是否创建表格

或打印无。但这显然是不可能的。


我错过了什么吗?


谢谢!

马克

Hello,

I''m trying to solve an XSLT problem, and I''m hoping someone can give a
little guidance. I am transforming XML to HTML.

Here''s an example of the XML file I''m dealing with, greatly simplified:

-----------------
<root>

<object name="a">
<item name="a1">Text here</item>
<item name="readonlya2">Text here</item>
<item name="a3">Text here</item>
<item name="readonlya4">Text here</item>
<item name="a5">Text here</item>
</object>

<object name="b">
<item name="b1">Text here</item>
<item name="b2">Text here</item>
<item name="b3">Text here</item>
<item name="b4">Text here</item>
<item name="b5">Text here</item>
</object>

</root>
----------------------

An <object> element contains several <item> elements. I handle each
<object> separately.

If an <object> contains no read-only <item> elements (identified by
name="readonly.."), I want to print "None" in the HTML output.

If there is one or more read-only <item> in an <object>, I will display
those read-only <item> elements in an HTML table.

It seemed simple, but I have tried using a key, and a recursive
template, and anything else I could think of. I can''t find out if there
are any read-only <item>s before putting something in the result tree.
If I could set a global variable from within a template, then it would
be easy to check that variable to tell whether or not to create a table
or print "None." But that is apparently not possible.

Have I missed something?

Thanks!
Mark

推荐答案



" ned786" < N7 ** @ earthlink.net>在消息中写道

news:11 ********************** @ g14g2000cwa.googlegr oups.com ...

"ned786" <n7**@earthlink.net> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
你好,

我正在努力解决XSLT问题,我希望有人可以提供一点指导。我正在将XML转换为HTML。

这是我正在处理的XML文件的一个例子,大大简化了:

------- ----------
< root>

< object name =" a">
< item name =" a1" >这里的文字< / item>
< item name =" readonlya2">这里的文字< / item>
< item name =" a3">这里的文字< / item>
< item name =" readonlya4"> Text here< / item>
< item name =" a5"> Text here< / item>
< / object> ;

< object name =" b">
< item name =" b1"> Text here< / item>
< item name = " b2">文字在这里< / item>
< item name =" b3">文字在这里< / item>
< item name =" b4">文字在这里< ; / item>
< item name =" b5">文字在这里< / item> ;
< / object>

< / root>
---------------------- < br&>
< object> element包含多个< item>元素。我处理每个
< object>单独。

如果< object>不包含只读< item>元素(由
name =" readonly .."标识),我想打印无。在HTML输出中。

如果有一个或多个只读< item>在< object>中,我将显示
那些只读< item> HTML表格中的元素。

这看起来很简单,但我尝试过使用密钥和递归模板,以及我能想到的任何其他内容。在将某些内容放入结果树之前,我无法确定是否有任何只读< item>。
如果我可以在模板中设置全局变量,那么它会
很容易检查该变量,以判断是否创建表格
或打印无。但这显然是不可能的。
Hello,

I''m trying to solve an XSLT problem, and I''m hoping someone can give a
little guidance. I am transforming XML to HTML.

Here''s an example of the XML file I''m dealing with, greatly simplified:

-----------------
<root>

<object name="a">
<item name="a1">Text here</item>
<item name="readonlya2">Text here</item>
<item name="a3">Text here</item>
<item name="readonlya4">Text here</item>
<item name="a5">Text here</item>
</object>

<object name="b">
<item name="b1">Text here</item>
<item name="b2">Text here</item>
<item name="b3">Text here</item>
<item name="b4">Text here</item>
<item name="b5">Text here</item>
</object>

</root>
----------------------

An <object> element contains several <item> elements. I handle each
<object> separately.

If an <object> contains no read-only <item> elements (identified by
name="readonly.."), I want to print "None" in the HTML output.

If there is one or more read-only <item> in an <object>, I will display
those read-only <item> elements in an HTML table.

It seemed simple, but I have tried using a key, and a recursive
template, and anything else I could think of. I can''t find out if there
are any read-only <item>s before putting something in the result tree.
If I could set a global variable from within a template, then it would
be easy to check that variable to tell whether or not to create a table
or print "None." But that is apparently not possible.




使用:


< xsl:stylesheet version =" 1.0"

xmlns:xsl =" http://www.w3.org/1999/XSL/Transform">

< xsl:output method =" html" />


< xsl:template match =" object">

< xsl:choose>

< xsl:when test =" not(* [starts-with(@ name,''readonly'')])">



< ; / xsl:when>

< xsl:otherwise>

< table>

< xsl:for-each select =" ; * [starts-with(@ name,''readonly'')]">

< tr>< td>< xsl:value-of select =" @ name" ; />< / td>< / tr>

< / xsl:for-each>

< / table>

< / xsl:否则>

< / xsl:选择>

< / xsl:template>

< / xsl:stylesheet>



Use:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>

<xsl:template match="object">
<xsl:choose>
<xsl:when test="not(*[starts-with(@name,''readonly'')])">
None
</xsl:when>
<xsl:otherwise>
<table>
<xsl:for-each select="*[starts-with(@name,''readonly'')]">
<tr><td><xsl:value-of select="@name"/></td></tr>
</xsl:for-each>
</table>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>


谢谢!我会检查一下。它适用于我简化的XML文件,

我会看到我对真实内容的看法。


我不知道你可以放一个谓词[...]在星号(*)上,如

* [start-with ... etc]。


Mark

Thank you! I will check this out. It worked on my simplified XML file,
I will see what I get on the real thing.

I didn''t know you could put a predicate [...] on an asterisk (*), as in
*[starts-with...etc].

Mark


ned786写道:
ned786 wrote:
您好,

我正在尝试解决XSLT问题,我希望有人可以提供一点指导。我正在将XML转换为HTML。

这是我正在处理的XML文件的一个例子,大大简化了:

------- ----------
< root>

< object name =" a">
< item name =" a1" >这里的文字< / item>
< item name =" readonlya2">这里的文字< / item>
< item name =" a3">这里的文字< / item>
< item name =" readonlya4"> Text here< / item>
< item name =" a5"> Text here< / item>
< / object> ;

< object name =" b">
< item name =" b1"> Text here< / item>
< item name = " b2">文字在这里< / item>
< item name =" b3">文字在这里< / item>
< item name =" b4">文字在这里< ; / item>
< item name =" b5">发短信给他re< / item>
< / object>

< / root>
------------------- ---

< object> element包含多个< item>元素。我处理每个
< object>单独。

如果< object>不包含只读< item>元素(由
name =" readonly .."标识),我想打印无。在HTML输出中。

如果有一个或多个只读< item>在< object>中,我将显示
那些只读< item> HTML表格中的元素。

这看起来很简单,但我尝试过使用密钥和递归模板,以及我能想到的任何其他内容。在将某些内容放入结果树之前,我无法确定是否有任何只读< item> s。


< xsl:template match =" object">

< xsl:variable name =" roi"

select =" count(item [starts-with(@ name,''readonly'')])" />

< xsl:choose>

< xsl:when test ="
Hello,

I''m trying to solve an XSLT problem, and I''m hoping someone can give a
little guidance. I am transforming XML to HTML.

Here''s an example of the XML file I''m dealing with, greatly simplified:

-----------------
<root>

<object name="a">
<item name="a1">Text here</item>
<item name="readonlya2">Text here</item>
<item name="a3">Text here</item>
<item name="readonlya4">Text here</item>
<item name="a5">Text here</item>
</object>

<object name="b">
<item name="b1">Text here</item>
<item name="b2">Text here</item>
<item name="b3">Text here</item>
<item name="b4">Text here</item>
<item name="b5">Text here</item>
</object>

</root>
----------------------

An <object> element contains several <item> elements. I handle each
<object> separately.

If an <object> contains no read-only <item> elements (identified by
name="readonly.."), I want to print "None" in the HTML output.

If there is one or more read-only <item> in an <object>, I will display
those read-only <item> elements in an HTML table.

It seemed simple, but I have tried using a key, and a recursive
template, and anything else I could think of. I can''t find out if there
are any read-only <item>s before putting something in the result tree.
<xsl:template match="object">
<xsl:variable name="roi"
select="count(item[starts-with(@name,''readonly'')])"/>
<xsl:choose>
<xsl:when test="


这篇关于另一个XSLT问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆