XSLT和XSD [英] XSLT and XSD

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

问题描述

我在topxml.com上发布了此消息,没有人回应,所以我希望

有人可以帮助我。我正在关注VS.NET中的一些教程。

我创建了一个XSD架构文件,然后从那里创建了一个XML文件。

一切正常,我的数据经过验证架构。现在

当我尝试使用xsl显示我的xml它不会工作,除非我摆脱指向我的架构的xml文件的xmlns属性的
。为什么

我需要摆脱xml显示的属性?

I posted this on topxml.com and nobody has responded so I was hoping
somebody could help me here. I am following some tutorials in VS.NET.
I created a XSD schema file and then from there created an XML file.
Everything works okay and my data is validated against the schema. Now
when I try to display my xml using xsl it won''t work unless I get rid
of the xmlns property of the xml file that points to my schema. Why
would I need to get rid of that property for the xml to display?

推荐答案

这是一个非常常见问题。阅读例如:


我的XPath选择语句都不会对XML文件起作用,而

是一个默认命名空间。帮助!

作者Mark Bosley


at: http://www.topxml.com/people/bosley/defaultns.asp


=====

干杯,

Dimitre Novatchev。
http://fxsl.sourceforge.net/ - FXSL的主页

" Mark Constant" <共******* @ mix-net.net>在消息中写道

news:ce ************************** @ posting.google.c om ...
This is a very FAQ. Read for example:

None of my XPath select statements will work going against an XML file with
a default namespace. Help!
by Mark Bosley

at: http://www.topxml.com/people/bosley/defaultns.asp

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
"Mark Constant" <co*******@mix-net.net> wrote in message
news:ce**************************@posting.google.c om...
我在topxml.com上发布了此消息,没有人回复,所以我希望有人可以帮助我。我正在关注VS.NET中的一些教程。
我创建了一个XSD模式文件,然后从那里创建了一个XML文件。
一切正常,我的数据根据​​模式进行验证。现在,当我尝试使用xsl显示我的xml时,除非我摆脱指向我的架构的xml文件的xmlns属性,否则它将无法工作。为什么
我需要摆脱xml显示的属性?
I posted this on topxml.com and nobody has responded so I was hoping
somebody could help me here. I am following some tutorials in VS.NET.
I created a XSD schema file and then from there created an XML file.
Everything works okay and my data is validated against the schema. Now
when I try to display my xml using xsl it won''t work unless I get rid
of the xmlns property of the xml file that points to my schema. Why
would I need to get rid of that property for the xml to display?



我有一个稍微不同的问题,我可以'找不到出路。

我没有使用显式的默认命名空间,但是我遇到了结果树元素中不需要的命名空间声明的着名

问题:


在TopXml上取样并略微更改:

<?xml version =" 1.0" encoding =" UTF-8"?>


< requestHierarchySelectResult resultName =""

xmlns:cs =" http:// www.customsolids.com">


< request>


< created_dt> 05/05/2000 00:00:00< ; / created_dt>


< created_tm> 01/01/1900 14:02:46< / created_tm>


< cs: request_id>


< my_value> 12345< / my_value>


< / cs:request_id>


< / request>

< / requestHierarchySelectResult>


<?xml version =" 1.0" encoding =" UTF-8"?>


< xsl:stylesheet


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


xmlns:cs =" http://www.customsolids.com"


version =" 1.0"


exclude-result-prefixes =" cs">


< xsl:output indent =" yes" />


< xsl:template match =" /">


< out> ;


< xsl:apply-templates select =" // cs:request_id / my_value" />


< / out>


< / xsl:template>


< xsl:template match =" * | @ * | node() " />


< xsl:template match =" my_value">


< xsl:copy>


< xsl:value-of select ="。" />


< / xsl:copy>


< / xsl:template>


< / xsl:stylesheet>


结果是:


<?xml version =" 1.0" encoding =" UTF-8"?>


< out>


< my_value xmlns:cs =" http: //www.customsolids.com">12345</my_value>


< / out>


我的问题是,如何摆脱xmlns:cs命名空间声明里面

< my_value>?


再见,


Flavio

I have a slightly different problem instead and I can''t find the way out.
I am not using an explicit default namespace, but I am hitting the famous
problem of the unwanted namespace declarations inside result tree elements:

Take the samples at TopXml and change them slightly:
<?xml version="1.0" encoding="UTF-8"?>

<requestHierarchySelectResult resultName=""
xmlns:cs="http://www.customsolids.com">

<request>

<created_dt>05/05/2000 00:00:00</created_dt>

<created_tm>01/01/1900 14:02:46</created_tm>

<cs:request_id>

<my_value>12345</my_value>

</cs:request_id>

</request>

</requestHierarchySelectResult>

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet

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

xmlns:cs="http://www.customsolids.com"

version="1.0"

exclude-result-prefixes="cs">

<xsl:output indent="yes"/>

<xsl:template match="/">

<out>

<xsl:apply-templates select="//cs:request_id/my_value"/>

</out>

</xsl:template>

<xsl:template match="*|@*|node()"/>

<xsl:template match="my_value">

<xsl:copy>

<xsl:value-of select="."/>

</xsl:copy>

</xsl:template>

</xsl:stylesheet>

The result is:

<?xml version="1.0" encoding="UTF-8"?>

<out>

<my_value xmlns:cs="http://www.customsolids.com">12345</my_value>

</out>

My question is, how to get rid of the xmlns:cs namespace declararion inside
<my_value>?

Bye,

Flavio




" FC" < FL **** @ tin.it>在消息中写道

news:ex *********************** @ news2.tin.it ...

"FC" <fl****@tin.it> wrote in message
news:ex***********************@news2.tin.it...
我有一个稍微不同的问题,我找不到出路。
我没有使用显式的默认命名空间,但我遇到了不受欢迎的命名空间的着名问题结果树中的声明
元素:
在TopXml中取样并略微更改:

<?xml version =" 1.0" encoding =" UTF-8"?>

< requestHierarchySelectResult resultName =""
xmlns:cs =" http://www.customsolids.com">

< request>

< created_dt> 05/05/2000 00:00:00< / created_dt>

< created_tm> 01/01/1900 14:02:46< / created_tm>

< cs:request_id>

< my_value> 12345< / my_value>

< / cs:request_id>

< / request>
< / requestHierarchySelectResult>

<?xml version = " 1.0" encoding =" UTF-8"?>

< xsl:stylesheet

xmlns:xsl =" http://www.w3.org/1999/ XSL /转换

xmlns:cs =" http://www.customsolids.com"

version =" 1.0"
exclude-result-prefixes =" cs">

< xsl:output indent =" yes" />

< xsl:template match = " /">

< out>

< xsl:apply-templates select =" // cs:request_id / my_value" />

< / out>

< / xsl:template>
< xsl:template match =" * | @ * | node ()" />

< xsl:template match =" my_value">

< xsl:copy>

< xsl:value-of select ="。" />

< / xsl:copy>

< / xsl:template>

< / xsl:stylesheet>

结果是:

<?xml version =" 1.0" encoding =" UTF-8"?>

< out>

< my_value xmlns:cs =" http://www.customsolids.com" > 12345< / my_value>

< / out>

我的问题是,如何摆脱xmlns:cs命名空间声明
inside< my_value>?
I have a slightly different problem instead and I can''t find the way out.
I am not using an explicit default namespace, but I am hitting the famous
problem of the unwanted namespace declarations inside result tree elements:
Take the samples at TopXml and change them slightly:
<?xml version="1.0" encoding="UTF-8"?>

<requestHierarchySelectResult resultName=""
xmlns:cs="http://www.customsolids.com">

<request>

<created_dt>05/05/2000 00:00:00</created_dt>

<created_tm>01/01/1900 14:02:46</created_tm>

<cs:request_id>

<my_value>12345</my_value>

</cs:request_id>

</request>

</requestHierarchySelectResult>

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet

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

xmlns:cs="http://www.customsolids.com"

version="1.0"

exclude-result-prefixes="cs">

<xsl:output indent="yes"/>

<xsl:template match="/">

<out>

<xsl:apply-templates select="//cs:request_id/my_value"/>

</out>

</xsl:template>

<xsl:template match="*|@*|node()"/>

<xsl:template match="my_value">

<xsl:copy>

<xsl:value-of select="."/>

</xsl:copy>

</xsl:template>

</xsl:stylesheet>

The result is:

<?xml version="1.0" encoding="UTF-8"?>

<out>

<my_value xmlns:cs="http://www.customsolids.com">12345</my_value>

</out>

My question is, how to get rid of the xmlns:cs namespace declararion inside <my_value>?



简短的回答是:你得到你指定的内容 - 复制元素副本

所有命名空间节点。这个元素不是文字结果元素,所以

exclude-result-prefixes不适用于它。


另外,复制的含义是按原样复制节点而不做任何更改。这个

意味着必须复制节点的所有命名空间节点。


实现你想要的用途:


< xsl:template match =" my_value">

< xsl:element name =" {name()}">

< ; xsl:value-of select ="。" />

< / xsl:element>

< / xsl:template>


=====

欢呼,

Dimitre Novatchev。
http://fxsl.sourceforge.net/ - FXSL的主页


The short answer is: You get what you specified -- copying an element copies
all its namespace nodes. This element is not a literal-result-element, so
exclude-result-prefixes does not apply to it.

Also, the meaning of copying is to copy the node as is with no change. This
means that all namespace nodes of the node must be copied.

To achieve what you want use:

<xsl:template match="my_value">
<xsl:element name="{name()}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

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

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