如何为前缀“tns”编写xpath?

时间:2015-09-19 11:26:09

标签: xml xslt xpath

我有3个文件

1-文件(XSD)

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://ex.com/baseballplayers" 
    xmlns:nttbp="http://www.ex.com/baseballplayers" elementFormDefault="qualified">

    <!-- I put this in here to act as a root element for the XML file -->
        <xs:element name="M1"/>

        <xs:element name="players">
....
            <xs:attribute name="name" type="xs:srting"></xs:attribute>
    </players>

2个文件(XML)

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="baseballplayers.xsl" ?>    
<nttbp:M1 xmlns:nttbp="http://www.ex.org/M1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.ex.org/M1 baseballplayers.xsd ">
        <nttbp:players name="John"></nttbp:players>

3-文件(XSL)

当我尝试编写一个XSL文件时,我不知道如何为元素“players”及其属性“name”编写Xpath,我试着像这样编写

<xsl:for-each select="../nttbp:players">

但在浏览器中显示此消息

  

加载样式表时出错:发生了未知错误()

请帮帮我

1 个答案:

答案 0 :(得分:0)

在样式表标题

中指定名称空间
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:nttbp="http://www.ex.org/M1">