0

我编写了一个 xsl,用于将我的 xml 文件的元素显示为编号列表。但我的 IE 浏览器并非每次都显示该列表。我想知道我的代码有什么问题。

这是我的 xsl 文件:

<?xml version = "1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/xsl/Transform">
<xsl:template match="/">
<html>
<body>
<ul>
<xsl:for-each select="Recipe/Ingredients/Ingredient">
<li><xsl:value-of select="name"/></li>
</xsl:for-each>
</ul> 
<ol>
<xsl:for-each select="Recipe/Steps/Step">
<li><xsl:value-of select="Action"/></li>
</xsl:for-each>
</ol>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

这是我的xml文件:

<?xml version = "1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="recipe.xsl"?>
<!DOCTYPE Recipe [
  <!ELEMENT Recipe (Ingredients, Steps, Nutrition)> 
  <!ATTLIST Recipe Recipe_name NMTOKEN #REQUIRED>
  <!ATTLIST Recipe Recipe_Lan (EN|FI|JP|CH) "EN">
  <!ELEMENT Ingredients (Ingredient+)> 
  <!ELEMENT Ingredient (name,Composedby?)>
  <!ELEMENT name (#PCDATA)> 
  <!-- PCDATA means the parsed character data, while CDATA refers to unparsed character data. so in an xml document, characters like"&",">" are illegal -->

  <!ELEMENT Composedby (Ingredient+)> 

  <!ATTLIST Ingredient Uni_ID ID #REQUIRED>
  <!ATTLIST Ingredient Amount CDATA #IMPLIED>
  <!ELEMENT Steps (Step+)>
  <!ELEMENT Step (Name, Action)>
  <!ELEMENT Name (#PCDATA)> 
  <!ELEMENT Action (#PCDATA)> 
  <!ATTLIST Step Duration CDATA #REQUIRED>
  <!ELEMENT Nutrition (Calories, Fat, Protain_amount)> 
  <!ELEMENT Calories (#PCDATA)> 
  <!ELEMENT Fat (#PCDATA)> 
  <!ELEMENT Protain_amount (#PCDATA)> 
]> 

<Recipe Recipe_name="Vinegar_pepper_Soup" Recipe_Lan="EN">
<Ingredients>
    <Ingredient Uni_ID="V1" Amount="500ml">
        <name>chicken broth</name>
        <Composedby>
            <Ingredient Uni_ID="V2" Amount="100g">
                <name>chicken</name>
            </Ingredient>
            <Ingredient Uni_ID="V3" Amount="500g">
                <name>water</name>
            </Ingredient>
        </Composedby>
    </Ingredient> 
    <Ingredient Uni_ID="V4" Amount="50g">
                <name>tofu</name>
    </Ingredient>
    <Ingredient Uni_ID="V5" Amount="10ml">
                <name>vinegar</name>
    </Ingredient>
    <Ingredient Uni_ID="V6" Amount="10g">
                <name>flour</name>
    </Ingredient>
    <Ingredient Uni_ID="V7" Amount="100g">
                <name>winter bamboo shoots</name>
    </Ingredient>
    <Ingredient Uni_ID="V8" Amount="30g">
                <name>carrot</name>
    </Ingredient>
    <Ingredient Uni_ID="V9" Amount="one">
                <name>egg</name>
    </Ingredient>
    <Ingredient Uni_ID="V10" Amount="15ml">
                <name>soya light</name>
    </Ingredient>
    <Ingredient Uni_ID="V11" Amount="5g">
                <name>white pepper powder</name>
    </Ingredient>
    <Ingredient Uni_ID="V12" Amount="10ml">
                <name>oil</name>
    </Ingredient>

</Ingredients>
<Steps>
    <Step Duration="3 minutes">
        <Name>Washing</Name>
        <Action>Wash all the stuffs</Action>
    </Step>
    <Step Duration="10 minutes">
        <Name>Cutting</Name>
        <Action>Cutting carrots, winter bamboo shoots and toufu into small pieces</Action>
    </Step>
    <Step Duration="3 minutes">
        <Name>Egg Beating</Name>
        <Action>Beat the egg</Action>
    </Step>
    <Step Duration="5 minutes">
        <Name>Stuffs frying</Name>
        <Action>Pour 10ml oil to the heated pot, wait until it gets warm, fry the cutting stuffs</Action>
    </Step>
    <Step Duration="3 minutes">
        <Name>Water flour</Name>
        <Action>Water the flour, pour it into the pot and stir</Action>
    </Step>
    <Step Duration="1 minutes">
        <Name>Egg liquid Pouring</Name>
        <Action>Pour the egg liquid to the pot and stir</Action>
    </Step>
    <Step Duration="1 minutes">
        <Name>Seasoning</Name>
        <Action>put the venigar, white pepper powder and soya light into the pot</Action>
    </Step>
</Steps>
<Nutrition>
        <Calories>50 cal per 100g</Calories>
        <Fat>5g per 100g</Fat>
        <Protain_amount>10g per 100g</Protain_amount>
</Nutrition>
</Recipe>

IE 浏览器显示如下:在此处输入图像描述

4

1 回答 1

0

您的 XSLT 命名空间 URI 错误,应该是

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

注意XSL大写。

于 2013-03-13T20:04:54.650 回答