仅使用XSLT变换更改少量标签

时间:2019-03-13 11:24:22

标签: xslt

我有一条大的json消息,我只想更改某些字段的值。其余字段应与输入消息完全相同地发送。无需在xslt中对每个项目进行硬编码,是否有办法仅更改所选项目?

XML输入有效载荷

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <glossary>
      <title>example glossary</title>
      <GlossDiv>
         <GlossList>
            <GlossEntry>
               <Abbrev>ISO 8879:1986</Abbrev>
               <Acronym>SGML</Acronym>
               <GlossDef>
                  <GlossSeeAlso>
                     <element>GML</element>
                     <element>XML</element>
                  </GlossSeeAlso>
                  <para>A meta-markup language, used to create markup languages such as DocBook.</para>
               </GlossDef>
               <GlossSee>markup</GlossSee>
               <GlossTerm>Standard Generalized Markup Language</GlossTerm>
               <ID>SGML</ID>
               <SortAs>SGML</SortAs>
            </GlossEntry>
         </GlossList>
         <title>S</title>
      </GlossDiv>
   </glossary>
</root>

有效载荷

{
    "glossary": {
        **"title": "example glossary",**
        "GlossDiv": {
            "title": "S",
            "GlossList": {
                "GlossEntry": {
                    "ID": "SGML",
                    "SortAs": "SGML",
                    "GlossTerm": "Standard Generalized Markup Language",
                    "Acronym": "SGML",
                    "Abbrev": "ISO 8879:1986",
                    "GlossDef": {
                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
                        "GlossSeeAlso": ["GML", "XML"]
                    },
                    "GlossSee": "markup"
                }
            }
        }
    }
}

预期产量

{
    "glossary": {
        **"title": "New value",**
        "GlossDiv": {
            "title": "S",
            "GlossList": {
                "GlossEntry": {
                    "ID": "SGML",
                    "SortAs": "SGML",
                    "GlossTerm": "Standard Generalized Markup Language",
                    "Acronym": "SGML",
                    "Abbrev": "ISO 8879:1986",
                    "GlossDef": {
                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
                        "GlossSeeAlso": ["GML", "XML"]
                    },
                    "GlossSee": "markup"
                }
            }
        }
    }
}

我对要更改的字段加粗了

1 个答案:

答案 0 :(得分:1)

从XML到XML,这是基本的XSLT

$scope.createUser=function()
{
    //console.log($scope.activeItem);
        //delete $scope.activeItem.hash_method
        var objectToSave = {
            username: console.log($scope.usernamee),
            password: console.log($scope.passwordd),
            name: console.log($scope.namee),
            id: $scope.id
        };
         {
            defaultAdapter.query('INSERT INTO users(username,password,name,id) VALUES(username = :usernamee, password = :passwordd,name = :namee WHERE id =:id)',
              { replacements: objectToSave, type: Sequelize.QueryTypes.UPDATE }
            ).then(projects => {
              console.log(projects);
              $scope.editMode = false;
                $scope.activeItem = false;
                $scope.refresh();
            });

        }
}

使用身份转换模板以及要转换的元素或属性(或一般而言的节点)的其他模板。

转换为JSON是另一个问题。