开发者

The elements do not fall into document('')

开发者 https://www.devze.com 2023-01-03 07:55 出处:网络
<?xml version=\"1.0\" encoding=\"windows-1251\"?> <xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">
<?xml version="1.0" encoding="windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="no" encoding="windows-1251"/>

<xsl:template match="/">
    <xsl:for-each select="document('')//w">
        <xsl:value-of select="@e"/>
    </xsl:for-each>
</xsl:template>

<my:translations xmlns:my="my:my">
    <w e="name" r="Название"/>
    <w e="model" r="Модель"/>
    <w e="year" r="Год"/>
    <w e="glass_type" r="Тип"/>
    <w e="scancode" r="Сканкод"/>
    <w e="eurocode" r="Еврокод"/>
    <w e="comment" r="开发者_Go百科Комментарий"/>
    <w e="glass_size" r="Размер"/>
    <w e="vendor" r="Производитель"/>
    <w e="trademark" r="Торговая марка"/>
    <w e="fprice" r="Цена"/>
</my:translations> 

</xsl:stylesheet>

I have no result. What the mistake?


Excuse my carelessness in the formulation of questions.


The most probable problem -- in the code that you politely haven't shown -- is a probable default namespace.

If this is the case (beside that I am good at fortune-telling) this will mean that the solution will look like the following:

document('')//x:w

where the prefic x: is bound to your default namespace.


There should not be any problem. This stylesheet:

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

<my:translations xmlns:my="my:my"> 
    <w e="name" r="Название"/> 
    <w e="model" r="Модель"/> 
    <w e="year" r="Год"/> 
    <w e="glass_type" r="Тип"/> 
    <w e="scancode" r="Сканкод"/> 
    <w e="eurocode" r="Еврокод"/> 
    <w e="comment" r="Комментарий"/> 
    <w e="glass_size" r="Размер"/> 
    <w e="vendor" r="Производитель"/> 
    <w e="trademark" r="Торговая марка"/> 
    <w e="fprice" r="Цена"/> 
</my:translations>  

<xsl:template match="/"> 
<root> 
<xsl:value-of select="count(document('')//w)"/>
</root> 
</xsl:template> 

</xsl:stylesheet> 

This is the result with any input:

<root>11</root>

Edit: With the new stylesheet you post, I get the expected result:

namemodelyearglass_typescancodeeurocodecommentglass_sizevendortrademarkfprice


Update: The OP has finally published his code. There is no problem in the code.

When the provided transformation:

<?xml version="1.0" encoding="windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="no" encoding="windows-1251"/>

<xsl:template match="/">
    <xsl:for-each select="document('')//w">
        <xsl:value-of select="@e"/>
    </xsl:for-each>
</xsl:template>

<my:translations xmlns:my="my:my">
    <w e="name" r="Название"/>
    <w e="model" r="Модель"/>
    <w e="year" r="Год"/>
    <w e="glass_type" r="Тип"/>
    <w e="scancode" r="Сканкод"/>
    <w e="eurocode" r="Еврокод"/>
    <w e="comment" r="Комментарий"/>
    <w e="glass_size" r="Размер"/>
    <w e="vendor" r="Производитель"/>
    <w e="trademark" r="Торговая марка"/>
    <w e="fprice" r="Цена"/>
</my:translations>

</xsl:stylesheet>

is run with 7 XSLT 1.0 processors and 2 XSLT 2.0 processors on any XML document (not used), all of them produce the same correct and wanted result:

namemodelyearglass_typescancodeeurocodecommentglass_sizevendortrademarkfprice
0

精彩评论

暂无评论...
验证码 换一张
取 消