从xml的图像标记到xslt获取值

从xml的图像标记到xslt获取值,xml,xslt,Xml,Xslt,这是我的xml代码。我想在Xslt中使用Image元素值,以便使用xml文档中的图像。请帮助我如何获取图像。我通过 我唯一的问题是图像传输 <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="work.xsl"?> <student> <studentlist> <S.No>1</S.No> <Nam

这是我的xml代码。我想在Xslt中使用Image元素值,以便使用xml文档中的图像。请帮助我如何获取图像。我通过 我唯一的问题是图像传输

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="work.xsl"?>
<student>
<studentlist>
    <S.No>1</S.No>
    <Name>Student1</Name>
    <E-mail>ab@xy.in</E-mail>
    <Qualification>MCA</Qualification>
    <createdon>6 Jan 2012</createdon>
    <Image><img src="/home/walkingtree/Desktop/hemanth practice/new/close-icon-41.jpg"/>
    <img src="/home/walkingtree/Desktop/hemanth practice/new/edit.jpg"/>
    </Image>
</studentlist>
<studentlist>
    <S.No>2</S.No>
    <Name>Student2</Name>
    <E-mail>cd@xy.in</E-mail>
    <Qualification>BE</Qualification>
    <createdon>7 Jan 2012</createdon>
    <Image><img src="/home/walkingtree/Desktop/hemanth practice/new/close-icon-41.jpg"/>
    <img src="/home/walkingtree/Desktop/hemanth practice/new/edit.jpg"/>
    </Image>
</studentlist>
<studentlist>
    <S.No>3</S.No>
    <Name>Student3</Name>
    <E-mail>ef@xy.in</E-mail>
    <Qualification>B.TECH</Qualification>
    <createdon>3 Jan 2012</createdon>
    <Image><img src="/home/walkingtree/Desktop/hemanth practice/new/close-icon-41.jpg"/>
    <img src="/home/walkingtree/Desktop/hemanth practice/new/edit.jpg"/>
    </Image>
</studentlist>
<studentlist>
    <S.No>4</S.No>
    <Name>Student4</Name>
    <E-mail>gh@xy.in</E-mail>
    <Qualification>MCA</Qualification>
    <createdon>23 Dec 2011</createdon>
    <Image><img src="/home/walkingtree/Desktop/hemanth practice/new/close-icon-41.jpg"/>
    <img src="/home/walkingtree/Desktop/hemanth practice/new/edit.jpg"/>
    </Image>
</studentlist>
</student>

1.
学生1
ab@xy.in
马华
2012年1月6日
2.
学生2
cd@xy.in
是
2012年1月7日
3.
学生3
ef@xy.in
理工学士
2012年1月3日
4.
学生4
gh@xy.in
马华
2011年12月23日
这是我的xslt代码。虽然有点长,但希望你能理解。我不知道我在每个循环中使用的格式是否正确。请帮我解决这个问题

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Login form</title>
<style>
input{
font: 1em sans-serif;
width: 300px;
box-sizing: border-box;
border: 1px solid #999;
}
.styled-select select {

}
#sel {
font: 1em sans-serif;
width: 230px;
height:31px;
box-sizing: border-box;
border: 2px solid #43C6DB;
height:31px;
background: #fafafa url("/home/walkingtree/Desktop/hemanth        practice/editalll/hello.jpg") no-repeat 100% 50%;
appearance:none;
 -webkit-appearance:none;
}
#form-setting{
display:none;
position:fixed;
left:620px;
top:5px;
width: 390px;
padding: 1em;
border: 1px solid #CCC;
border-radius: 15px 1px;
background-color:#BDEDFF;
}

form div + div {
margin-top: 1em;
}

label {
display: inline-block;
width: 110px;
text-align: left;
}

input{
 font: 1em sans-serif;
 width: 230px;
height:31px;
box-sizing: border-box;
border: 2px solid #43C6DB;
}
.button {
background-color: #89C35C;
border: none;
color: white;
padding: 10px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius:6px;
}
option{
height:20px;
}

.button2 {border-radius:6px;
background-color: #E55451;
float:right}

#close{position:fixed;
top:0px;
left:1040px;
cursor:pointer;
}
</style>
</head>
<body>
<div>
    <table border="0" cellspacing="0" width="600px">
        <tr>
            <th>
                <div style="background-color:#EF8224">
                    <table width="100%">
                        <tr>
                            <th style="float:left"><font color="white">StudentList</font></th>
                            <th style="float:right"><a href="#" onclick="poped()">Add</a></th>
                            <th style="float:right"><img src="/home/walkingtree/Desktop/adding.png" width="17px" align="right"/></th>
                        </tr>
                    </table>
                </div>
            </th>
        </tr>
        <tr>
            <td>
                <table width="100%">
                    <tr bgcolor="#EF8224">
                        <th style="text-align:left" width="100px">S.No.      </th>
                        <th style="text-align:left">Name</th>
                        <th style="text-align:left">Email</th>
                        <th style="text-align:left">Qualification</th>
                        <th style="text-align:left">CreatedOn</th>
                        <th style="text-align:left">Action</th>
                    </tr>
                    <xsl:for-each select="student/studentlist">
                    <tr style="background-color:#FFDFD6">
                        <td><xsl:value-of select="S.No"/></td>
                        <td><xsl:value-of select="Name"/></td>
                        <td><xsl:value-of select="E-mail"/></td>
                        <td><xsl:value-of select="Qualification"/></td>
                        <td><xsl:value-of select="createdon"/></td>
                        <td><img width="25x" height="25px" src="{/student/studentlist/Image/node()}" class="CalloutRightPhoto"/></td>
                    </tr>
                    </xsl:for-each>
                </table>
            </td>
        </tr>
    </table>
 </div>
 <div id="form-setting">    
    <p>
        <img id="close" src="/home/walkingtree/Desktop/hemanth practice/editalll/close-icon-41.jpg" width="10px" height="10px" onclick="closeform()"/>
    </p>
    <form>
        <table>
            <tr>
                <td>
                     <div>
                            <label for="name">Name<font color="red">* </font>:</label>
                            <input type="text" id="name" name="user_name"/>
                     </div>
                     <div>
                            <label for="mail">E-mail<font color="red">*</font>:</label>
                            <input type="email" id="mail" name="user_mail"/>
                     </div>
                    <div>
                        <label for="qual">Qualification:</label>
                        <select id="sel">
                            <option value=""></option>
                                <option value="MCA">MCA</option>
                                <option value="B.Tech">B.Tech</option>
                        </select>
                        </div>
                </td>
            </tr>

                <tr style="width:100%">
                    <td align="right" style="float:right">
                        <button class="button">submit</button>
                        <button class="button button2">reset</button> 
                    </td>
                </tr>

        </table>
    </form>
 </div>
<script type="text/javascript">
var v=document.getElementById("form-setting");
function poped(){
v.style.display="block";
}
function closeform(){
v.style.display="none"
}
</script>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

登录表格
输入{
字体:1em无衬线;
宽度:300px;
框大小:边框框;
边框:1px实心#999;
}
.样式选择{
}
#选择{
字体:1em无衬线;
宽度:230px;
高度:31px;
框大小:边框框;
边框:2px实心#43C6DB;
高度:31px;
背景:#fafafaurl(“/home/walkingtree/Desktop/hemanthpractice/editalll/hello.jpg”)不重复100%50%;
外观:无;
-webkit外观:无;
}
#定形{
显示:无;
位置:固定;
左:620px;
顶部:5px;
宽度:390px;
填充:1em;
边框:1px实心#CCC;
边界半径:15px 1px;
背景色:#BDEDFF;
}
表格div+div{
边缘顶部:1米;
}
标签{
显示:内联块;
宽度:110px;
文本对齐:左对齐;
}
输入{
字体:1em无衬线;
宽度:230px;
高度:31px;
框大小:边框框;
边框:2px实心#43C6DB;
}
.按钮{
背景色:#89C35C;
边界:无;
颜色:白色;
填充:10px 25px;
文本对齐:居中;
文字装饰:无;
显示:内联块;
字体大小:16px;
利润:4倍2倍;
光标:指针;
边界半径:6px;
}
选择权{
高度:20px;
}
.按钮2{边界半径:6px;
背景色:#E55451;
float:right}
#关闭{位置:固定;
顶部:0px;
左:1040px;
光标:指针;
}
学生名单
没有。
名称
电子邮件
资格
CreatedOn
行动

姓名*: 电子邮件*: 资格: 马华 B.技术 提交 重置 var v=document.getElementById(“表单设置”); 函数poped(){ v、 style.display=“block”; } 函数closeform(){ v、 style.display=“无” }
这是我从这段代码中得到的输出。正如你所看到的,动作没有显示任何图片

这是我需要得到的输出。

这一行有问题:

<img width="25x" height="25px" src="{/student/studentlist/Image/node()}" class="CalloutRightPhoto"/>
注意在为
img
元素创建
src
属性时使用了s。大括号表示要计算的表达式,因此执行
{@src}
意味着获取当前
img
元素中
src
属性的值

如果要在图像中添加
onclick
操作,可以,但需要一种区分图像的方法。也许是这样的

<xsl:for-each select="Image/img">
    <img width="25px" height="25px" src="{@src}" class="CalloutRightPhoto">
        <xsl:attribute name="onclick">
            <xsl:choose>
                <xsl:when test="contains(@src, 'close-icon-41.jpg')">
                    <xsl:text>doClose();</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>doEdit();</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:attribute>
    </img>
</xsl:for-each>

doClose();
doEdit();

您好,您可以看到,在我的代码中还有其他字段,我得到了与图像有关的所有值。请澄清您想要实现的目标以及您迄今为止尝试的目标。发布导致您出现问题的XSLT代码以及您试图生成的所需输出。@Thomas W更新了我的问题。.希望您能理解并感谢您的回答。这就是我所寻找的。.您能解释一下src是如何工作的吗?如果可以,您可以用任何onclick功能添加这些图像吗?如果可以,您可以怎么做。.提前谢谢扩展了我的答案来解释更多。谢谢@Tim C。这段代码解决了我的问题。所以在上面的代码中,u给出了属性name=“onclick”所以这个名字是一个内置的名字,在conatins src中,它不需要提及图像的整个路径??这是我的另一个问题。如果你能在这方面提供帮助,那就太好了。这只是一个例子。如果您的图像需要不同的操作,您将需要一种方法来确定哪些操作与哪个图像相匹配。
<xsl:for-each select="Image/img">
    <img width="25px" height="25px" src="{@src}" class="CalloutRightPhoto">
        <xsl:attribute name="onclick">
            <xsl:choose>
                <xsl:when test="contains(@src, 'close-icon-41.jpg')">
                    <xsl:text>doClose();</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>doEdit();</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:attribute>
    </img>
</xsl:for-each>