小编Dim*_*hev的帖子

如何使用xslt过滤xml中的节点..?

假设我有这个xml:

<college>
    <student>
        <name>amit</name>
        <file>/abc/kk/final.c</file>
        <rollno>22</rollno>
    </student>
    <student>
        <name>sumit</name>
        <file>/abc/kk/up.h</file>
        <rollno>23</rollno>
    </student>
    <student>
        <name>nikhil</name>
        <file>/xyz/up.cpp</file>
        <rollno>24</rollno>
    </student>
    <student>
        <name>bharat</name>
        <file>/abc/kk/down.h</file>
        <rollno>25</rollno>
    </student>
    <student>
        <name>ajay</name>
        <file>/simple/st.h</file>
        <rollno>27</rollno>
    </student>
</college>
Run Code Online (Sandbox Code Playgroud)

我在".xsl"中使用for-each来显示节点的所有条目,但我只想显示那些文件名以"/ abc/kk"开头的那些节点的条目,因为我是xslt的新手. .

请给我解决方案.

我在用 :

<xsl:for-each select="college/student">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="file"/></td>
<td><xsl:value-of select="rollno"/></td>
</tr>
Run Code Online (Sandbox Code Playgroud)

xslt

3
推荐指数
1
解决办法
2万
查看次数

使用XSLT进行位置分组

我有xml,其中包含一些文档:

<document>
    <line id="0">
        <field id="0"><![CDATA[H:doc1]]></field>
    </line>
    <line id="1">
        <field id="0"><![CDATA[L:1]]></field>
    </line>
    <line id="2">
        <field id="0"><![CDATA[L:2]]></field>
    </line>
    <line id="3">
        <field id="0"><![CDATA[L:3]]></field>
    </line>
    <line id="4">
        <field id="0"><![CDATA[H:doc2]]></field>
    </line>
    <line id="5">
        <field id="0"><![CDATA[L:1]]></field>
    </line> 
</document>
Run Code Online (Sandbox Code Playgroud)

H =文档标题,L =行项目.在这个例子中,有两个H表示两个文件,它们编号为doc1和doc2.doc1有三个订单项,doc2有一个订单项.

如何使用xslt版本1转换数据以获得此结果:

<documents>
    <document>
        <header>
            <number>doc1</number>
        </header>
        <line-item>
            <line-number>1</line-number>
            <line-number>2</line-number>
            <line-number>3</line-number>
        </line-item>
    </document>
    <document>
        <header>
            <number>doc2</number>
        </header>
        <line-item>
            <line-number>1</line-number>
        </line-item>
    </document>
</documents>
Run Code Online (Sandbox Code Playgroud)

xslt

3
推荐指数
1
解决办法
316
查看次数

限制字符串中的字符数 - XSLT

我正在使用第三方asp.net控件来从数据库中提取和显示最新内容.该控件使用xsl文件提取最新发布内容的标题.我的问题是标题(内容片段)太长.我以前用过的地方显示没有大约100个字符的空间.我需要修剪(不是白色空格)结束部分,并可能将其限制为几个单词或一些字符.它使用xsl文件 -

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <table border="0" cellspacing="0" cellpadding="0" width="100%">
            <xsl:for-each select="Collection/Content">
                <tr>
                    <td>
                        <a>
                            <xsl:attribute name="href">
                                <xsl:choose>
                                    <xsl:when test="Type ='Assets' or Type = 8 ">
                                        javascript:void window.open('showcontent.aspx?id=<xsl:value-of select="ID"/>')
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="QuickLink"/>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:attribute>
                            <xsl:value-of select="Title"/>
                        </a>
                    </td>
                </tr>
            </xsl:for-each>
        </table>
    </xsl:template>
Run Code Online (Sandbox Code Playgroud)

这一部分,<xsl:value-of select="Title"/>是你的标题所在,我需要缩短它...(也许......最后......)

我该怎么做?我可以在不使用JQuery的情况下在xsl文件中完成此操作吗?非常感谢,

asp.net xslt xpath character limit

3
推荐指数
1
解决办法
1万
查看次数

如何在OSGi Bundle中使用Java扩展执行XSLT转换

我们正在将现有代码转换为OSGi环境.在我们的一个(尚未)OSGi包中,我们有代码执行XSLT转换.一段XSLT包含一个java扩展函数,用于创建唯一的数值.Java类也驻留在bundle中.这是样式表的一个片段:

<xsl:template match="m:property">
   <xsl:variable name="uniqueDataStreamName" select="concat(../@id,'/',@name)" />
   <xsl:variable name="uniqueDataStreamId"
       select="java:com.xyz.TransformationUtils.makeDataStreamIdFromUniqueName($uniqueDataStreamName)" />
   <data id="{number($uniqueDataStreamId)}">
   <tag>
      <xsl:value-of select="$uniqueDataStreamName" />
   </tag>
   <current_value>
     <xsl:value-of select="@value" />
  </current_value>
</data>
Run Code Online (Sandbox Code Playgroud)

作为参考,这是如何设置和调用转换:

protected Templates createTemplates(Source xsltSource) {
    try {
        TransformerFactory tf = TransformerFactory.newInstance();
        Templates templates = tf.newTemplates(xsltSource);
        return templates;
    } catch (TransformerException e) {
        throw new RuntimeException(e);
    }
}


protected byte[] transform(byte[] input) throws TransformerException {
    ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
    templates.newTransformer().transform(
            new StreamSource(new ByteArrayInputStream(input)),
            new StreamResult(out));
    return out.toByteArray();
}
Run Code Online (Sandbox Code Playgroud)

在非OSGi environemnt中运行时,它可以工作.在OSGi框架中运行时,它会失败,因为无法编译样式表,因为找不到类TransformationUtils.我有点明白 - 加载jaxp转换器实现的类加载器在我们的bundle中没有看到扩展类.但是,我很难找到解决方案.我尝试过使用OSGi:使用Xalan和Xerces捆绑无济于事.

我的问题是:如何解决这个问题?它可以?

xslt osgi classloader

3
推荐指数
1
解决办法
1376
查看次数

使用C#在内存中进行XSLT转换

大家下午好,

我不知道为什么这证明是如此困难,但我必须有其中一天!

我试图在内存中执行XslCompiledTransform XmlDocument(我已从Web服务检索XML并保存到数据库中)对象.到目前为止,我有以下代码:

        string xslFile = "C:\\MOJLogViewer\\GetClaimTransformed.xslt";

        XslCompiledTransform processor = new XslCompiledTransform();
        processor.Load(xslFile);

        MemoryStream ms = new MemoryStream();
        processor.Transform(xdoc.CreateNavigator(), null, ms);

        ms.Seek(0, SeekOrigin.Begin);

        StreamReader reader = new StreamReader(ms);

        XmlDocument transformedDoc = new XmlDocument();
        transformedDoc.Load(reader.ReadToEnd());


        string output = reader.ReadToEnd();
        ms.Close();
Run Code Online (Sandbox Code Playgroud)

当我尝试运行此代码时,我得到"路径中的非法字符"异常.该路径不包含任何非法字符,所以我绝对难倒!

我希望你能提供帮助.

谢谢

.net c# xml xslt xmldocument

3
推荐指数
1
解决办法
6873
查看次数

"禁止执行'document()'功能." 其中EnableDocumentFunction设置为true?

在尝试xslt转换时,我在生产环境中得到间歇性的System.Xml.Xsl.XslTransformException异常,遗憾的是我无法在开发环境中复制它.

该例外情况进一步详述:

禁止执行'document()'功能.使用XsltSettings.EnableDocumentFunction属性启用它.C:\ path\to\file\CDS.xsl(16,3)发生错误.

然而,EnableDocumentFunction属性设置为true的处理代码:

private void Transform()
{
    var keepTrying = true;
    var tryCount = 0;
    const int maxRetrys = 3;

    while (keepTrying)
    {
        try
        {
            var xmlResolver = new XmlUrlResolver();

            using (var xmlFile = new XmlNodeReader(_xDoc))
            {
                var settings = new XmlReaderSettings
                                   {
                                       XmlResolver = xmlResolver,
                                       ProhibitDtd = false,
                                       DtdProcessing = DtdProcessing.Ignore
                                   };

                using (var xsl = XmlReader.Create(_xslPath, settings))
                {
                    var xslt = new XslCompiledTransform(true);
                    xslt.Load(xsl, new XsltSettings { EnableDocumentFunction = true }, xmlResolver);

                    var sb …
Run Code Online (Sandbox Code Playgroud)

.net c# xml xslt c#-4.0

3
推荐指数
1
解决办法
9627
查看次数

使用XSLT将dateand以XML格式转换为UTC时区

我有一个XML文档,其日期为标准ISO 8601格式.像这样:


2011-11-29T04:15:22-08:00

我想使用XSLT将时间转换为以下格式的UTC和输出日期:


2011-11-29 12:15:22

怎么做到呢?

提前致谢.

xml xslt

3
推荐指数
1
解决办法
1万
查看次数

如何使用Nokogiri选择冒号?

有人认为在所有的ID名称中使用冒号是很棒的,所以现在我一直试图选择那些ID名称.

我正在使用Nokogiri,我需要选择ID为的项目tapListResultForm:resDetail_pg_3.

如: <span id="tapListResultForm:resDetail_pg_3">Example</span>

我试过这个:

doc = Nokogiri.HTML(html)
doc.css('#tapListResultForm:resDetail_pg_3')
Run Code Online (Sandbox Code Playgroud)

但是抛出一个RuntimeError: RuntimeError: xmlXPathCompOpEval: function resDetail_pg_3 not found

css ruby nokogiri

3
推荐指数
1
解决办法
507
查看次数

识别XSLT中的null元素,即使在子元素中也没有值

检查Null元素

<image><a><img src="abcd"/></a></image>
Run Code Online (Sandbox Code Playgroud)

XSLT模板:

<xsl:if test="image!=''">
IMAGE HAS TEXT OR INNER ELEMENT
</xsl:if>
Run Code Online (Sandbox Code Playgroud)

虽然"image"元素有子元素,但我得到空白输出.理想情况下它不是空的.

我必须检查它应该有值或子元素的条件.子元素可以为空.

如何纠正这一点.

谢谢

xslt xpath xslt-1.0

3
推荐指数
1
解决办法
1731
查看次数

xsl:sort:按数值排序

我必须按数字顺序整理代码.代码有四个字符和四个数字.

例如,

COMP2100
COMP2400
COMP3410
LAWS2202
LAWS2250
Run Code Online (Sandbox Code Playgroud)

当我这样做<xsl:sort select="code" order="ascending" /> 时显示上面的结果.

但是,我希望它是'数字顺序'

COMP2100
LAWS2202
COMP2250
COMP2400
COMP3410
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?

sorting xslt numerical

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

xslt ×9

xml ×3

.net ×2

c# ×2

xpath ×2

asp.net ×1

c#-4.0 ×1

character ×1

classloader ×1

css ×1

limit ×1

nokogiri ×1

numerical ×1

osgi ×1

ruby ×1

sorting ×1

xmldocument ×1

xslt-1.0 ×1