简体   繁体   English

使用xslt将XML转换为XML

[英]Transform XML to XML using xslt

As i said earlier I have started learning XSLT 正如我之前所说,我已经开始学习XSLT

When I am working on that I getting an wrong type of XML Format 当我这样做时,我得到了错误的XML格式类型

Input 输入项

<?xml version="1.0" encoding="ISO-8859-1"?>
<testingconfig note-ref="no">
<access-panel>113AL</access-panel>
<access-panel>119AL</access-panel>
</testingcongif>

Output 输出量

<?xml version="1.0" encoding="ISO-8859-1"?>
<testingconfig>
<panel><panelid>113AL</panelid></panel> 
<panel><panelid>119AL</panelid></panel> 
</testingconfig>

My XSL 我的XSL

<?xml version="1.0" encoding="ISO-8859-1"?>
<testingconfig>
    <xsl:for-each select="testingconfig">
    <panel>
        <panelid>
            <xsl:value-of select="*"/>
        </panelid>
    </panel>
</xsl:for-each>
</testingconfig>

Out put for this is 为此投入

<testingconfig>
<panel>
    <panelid>
        113AL 119AL
    </panelid>
</panel>
</testingconfig>

Can any one help me here where i am doing mistake and pls help me how to do it in XSLT 2.0 任何人都可以在这里做错的地方为我提供帮助吗,请帮助我如何在XSLT 2.0中做到这一点

Pls help me 请帮助我

Thanks & Regards M 谢谢与问候M

You just break it down into a set of transformation rules. 您只需将其分解为一组转换规则即可。 For example: 例如:

<xsl:template match="testingfig">
  <tscon><xsl:value-of select="."/></tscon>
</xsl:template>

<xsl:template match="config">
   <testingvalue>
       <testingtype>mar</testingtype>
       <testid>mar<xsl:value-of select="."/></testid>
   </testingvalue>
</xsl:template>

However, I'm a bit concerned that by giving you these examples I'm leading you by the hand into a swamp where you will get quickly stuck. 但是,我有点担心,通过提供这些示例,我将带领您进入沼泽,使您很快陷入困境。 It seems to me from your question that you are right at the beginning of learning this language, and asking on a forum for a solution to one simple problem is not really the best learning strategy. 从您的问题看来,在您开始学习这种语言时似乎是正确的,在论坛上要求解决一个简单问题并不是真正的最佳学习策略。 You can't learn a programming language by trial and error, or by copying noddy examples. 您不能通过反复试验或复制点头范例来学习编程语言。 You need to go away and read some books or tutorials. 您需要离开并阅读一些书籍或教程。

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
    <testingconfig>
        <xsl:for-each select="testingconfig/access-panel">
        <panel><panelid><xsl:value-of select="." /></panelid></panel>

        </xsl:for-each>
    </testingconfig>

</xsl:template>
</xsl:stylesheet>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM