Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何从xml中删除前缀/命名空间_Html_Xml_Xslt - Fatal编程技术网

Html 如何从xml中删除前缀/命名空间

Html 如何从xml中删除前缀/命名空间,html,xml,xslt,Html,Xml,Xslt,我有以下xml文件: <q1:GeneralAgenda xmlns="http://schemas.gov.sk/form/Notify.GeneralAgenda/1.1"> <q1:subject>text text text</q1:subject> <q1:text>lorem ipsum</q1:text> </q1:GeneralAgenda> 文本文本文本 乱数假文 我创建了xsl文件: <

我有以下xml文件:

<q1:GeneralAgenda xmlns="http://schemas.gov.sk/form/Notify.GeneralAgenda/1.1">
  <q1:subject>text text text</q1:subject>
  <q1:text>lorem ipsum</q1:text>
</q1:GeneralAgenda>

文本文本文本
乱数假文
我创建了xsl文件:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ga="http://schemas.gov.sk/form/Notify.GeneralAgenda/1.1">


<xsl:template match="ga:GeneralAgenda">
  <html>
   <head>

    </head> 
  <body>

   <div id="main" class="layoutMain">
      <div class="layoutRow ui-tabs ui-widget-content">
         <div class="caption ui-widget-header">
            <div class="headercorrection">Všeobecná agenda - oznámenie</div>
         </div>

         <div><label class="labelVis">Predmet: </label>

           <span class="contentVis wordwrap">

             <xsl:value-of select="ga:subject"/>

           </span>

        </div>

         <div class="clear"> </div>
         <div><label class="labelVis">Text: </label>
           <span class="contentVis wordwrap">

            <xsl:value-of select="ga:text"/>

           </span>
         </div>
         <div class="clear"> </div>
      </div>
   </div>

  </body>

  </html>
</xsl:template>

</xsl:stylesheet>

Všeobecnáagenda-oznámenie
预见面:
正文:

问题是,由于xml文件中的“q1:”部分,它无法工作,我如何更正这一点?我正在使用java从xml文件生成hmtl文件,当我手动删除q1时效果很好,我认为有一种方法可以调整xsl文件,但我不知道如何调整。

一般规则是:

  • 从XSLT脚本中删除显式的“用户”名称空间(但保留xsl 名称空间前缀)
  • 使用
    *[local-name()
因此,您可以使用下面这样的脚本,稍微修改一下您的脚本版本

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" doctype-public="-//W3C//DTD XHTML 1.1//EN"
    doctype-system= "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/>

  <xsl:template match="*[local-name() = 'GeneralAgenda']">
    <html>
      <head>
      </head> 
      <body>
        <div id="main" class="layoutMain">
          <div class="layoutRow ui-tabs ui-widget-content">
            <div class="caption ui-widget-header">
              <div class="headercorrection">Všeobecná agenda - oznámenie</div>
            </div>
            <div>
              <label class="labelVis">Predmet: </label>
              <span class="contentVis wordwrap">
                <xsl:value-of select="*[local-name() = 'subject']"/>
              </span>
            </div>
            <div class="clear"> </div>
            <div>
              <label class="labelVis">Text: </label>
              <span class="contentVis wordwrap">
                <xsl:value-of select="*[local-name() = 'text']"/>
              </span>
            </div>
            <div class="clear"> </div>
          </div>
        </div>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
否则会导致源XML格式不正确
甚至像Xalan这样的“基本”实现也失败了。

一般规则是:

  • 从XSLT脚本中删除显式的“用户”名称空间(但保留xsl 名称空间前缀)
  • 使用
    *[local-name()
因此,您可以使用下面这样的脚本,稍微修改一下您的脚本版本

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" doctype-public="-//W3C//DTD XHTML 1.1//EN"
    doctype-system= "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/>

  <xsl:template match="*[local-name() = 'GeneralAgenda']">
    <html>
      <head>
      </head> 
      <body>
        <div id="main" class="layoutMain">
          <div class="layoutRow ui-tabs ui-widget-content">
            <div class="caption ui-widget-header">
              <div class="headercorrection">Všeobecná agenda - oznámenie</div>
            </div>
            <div>
              <label class="labelVis">Predmet: </label>
              <span class="contentVis wordwrap">
                <xsl:value-of select="*[local-name() = 'subject']"/>
              </span>
            </div>
            <div class="clear"> </div>
            <div>
              <label class="labelVis">Text: </label>
              <span class="contentVis wordwrap">
                <xsl:value-of select="*[local-name() = 'text']"/>
              </span>
            </div>
            <div class="clear"> </div>
          </div>
        </div>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
否则会导致源XML格式不正确
甚至像Xalan这样的“基本”实现也失败了。

如果该输入被认为是命名空间格式良好的XML,那么它就没有为
q1
前缀(例如
q1:generalgenda
中使用的前缀)声明命名空间。因此,我认为XSLT处理器使用的任何XML解析器都不会得到该片段。如果该输入被认为是命名空间格式良好的XML,那么它就没有对
q1
前缀的命名空间声明,例如
q1:GeneralAgenda
。所以我认为XSLT处理器使用的任何XML解析器都不会得到这个片段。