如何选择一个命名空间中的XML元素? [英] How to select xml elements within a namespace?

查看:106
本文介绍了如何选择一个命名空间中的XML元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解这个XSLT。

什么是下面的XSLT命令来选择到底是什么?什么是跟随同胞,AIC和PSTYLE?

AIC似乎是一个名称空间。

什么XML输入与下面的XSLT工作的?

 <的xsl:样式排除-result- prefixes =AIC
    版本=1.0的xmlns:XSL =htt​​p://www.w3.org/1999/XSL/Transform的xmlns:AIC =htt​​p://ns.adobe.com/AdobeInCopy/2.0/><的xsl:模板匹配=/>    <的xsl:value-of的选择=以下同胞:: AIC:PSTYLE/>
< / XSL:模板>
< / XSL:样式>


解决方案

 以下同胞:: AIC:PSTYLE


  • 以下同胞的,表示要看其方向为节点,在这种情况下,它着眼于节点这是在文档顺序当前上下文节点之后,但共享相同的父,作为当前节点。如果没有指定的轴默认为孩子,它会查找当前上下文节点的子节点。


  • AIC:PSTYLE 是查找的的选择元素的,其本地名称为 PSTYLE 键,其名称空间URI http://ns.adobe.com/AdobeInCopy/2.0/ (即映射到preFIX <$之一C $ C> AIC 样式表)。


源XML不必使用相同的preFIX,例如恩pression将匹配,看起来像

元素

&LT; PSTYLE的xmlns =htt​​p://ns.adobe.com/AdobeInCopy/2.0/&GT;

 &LT;富:PSTYLE的xmlns:富=htt​​p://ns.adobe.com/AdobeInCopy/2.0/&GT;

在原始的XML。

由于JLRishe指出,这种特殊的XPath不会在当前上下文是文档节点 / ,为前pression有意义它会匹配任何在一个上下文,其中当前节点是一个元素将被执行(或评价,处理指令或文本节点)至少两个级别下即文档元素或更深的子

 &lt;例的xmlns =htt​​p://ns.adobe.com/AdobeInCopy/2.0/&GT;
  &所述; PSTYLE ID =1/&GT;
  &LT;富/&GT;
  &所述; PSTYLE ID =2/&GT;
  &所述; PSTYLE ID =3/&GT;
&LT; /示例&gt;

如果用元素作为上下文节点,前pression将选择PSTYLE元件2和3,但不执行1。

I'm trying to understand this xslt.

What does the below xslt command select exactly? what are "following-sibling", "aic" and "pstyle"?

"aic" seems to be a namespace.

What xml input the below xslt work with?

<xsl:stylesheet exclude-result-prefixes="aic" 
    version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aic="http://ns.adobe.com/AdobeInCopy/2.0/" >

<xsl:template match="/">

    <xsl:value-of select="following-sibling::aic:pstyle"/>
</xsl:template>
</xsl:stylesheet>

解决方案

following-sibling::aic:pstyle

  • following-sibling is the axis, denoting which "direction" to look for nodes, in this case it looks at nodes which are after the current context node in document order but share the same parent as the current node. If you don't specify an axis the default is child, which looks for child nodes of the current context node.

  • aic:pstyle is a selector that looks for elements whose local name is pstyle and whose namespace URI is http://ns.adobe.com/AdobeInCopy/2.0/ (the one that is mapped to the prefix aic in the stylesheet).

The source XML need not use the same prefix, e.g. the expression would match an element that looks like

<pstyle xmlns="http://ns.adobe.com/AdobeInCopy/2.0/">

or

<foo:pstyle xmlns:foo="http://ns.adobe.com/AdobeInCopy/2.0/">

in the original XML.

As JLRishe points out, this particular XPath will not match anything if the current context is the document node /, for the expression to be meaningful it would have to be executed in a context where the current node is an element (or comment, processing instruction or text node) at least two levels down i.e. a child of the document element or deeper.

<example xmlns="http://ns.adobe.com/AdobeInCopy/2.0/">
  <pstyle id="1"/>
  <foo/>
  <pstyle id="2"/>
  <pstyle id="3"/>
</example>

If executed with the foo element as the context node, the expression would select pstyle elements 2 and 3, but not 1.

这篇关于如何选择一个命名空间中的XML元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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