简体   繁体   中英

Search and pick up the xml tag using xslt code

I am new to xslt programming. I want help to get a piece of code for my requirement,

I have an xml file which is like

 <Tags>
 <tag>
 <value>abc</value>
 </tag>
 <tag>
 <value>def</value>
  </Tags>

The text inside value tags are the value of certain tags which will be present in the incoming xml request.

Now, I need an xslt code which would search if the incoming xml have any of the tags by looking into the list of tags which are present in the sample xml i have provided. If the tag is there than i want to save the value of that tag in a variable.

Thanks

I made XML snippet valid XML and stored it here: http://stamm-wilbrandt.de/en/forum/Tags.xml

Below stylesheet makes use of the power of XPath comparison between string value (the "name()" of current node) and a nodeset (all <value>s in Tags.xml):

$ coproc2 Tags.xsl <(echo '<d><abc/></d>') http://dp1-l3.boeblingen.de.ibm.com:2223
abc
$ 
$ cat Tags.xsl 
<!DOCTYPE xsl:stylesheet [ 
  <!ENTITY url "http://stamm-wilbrandt.de/en/forum/Tags.xml"> 
  <!ENTITY LF "<xsl:text>&#10;</xsl:text>">
]>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
  <xsl:output omit-xml-declaration="yes" />

  <xsl:variable name="tags" select="document('&url;')" />

  <xsl:template match="/">
    <xsl:for-each select="//*[name()=$tags/Tags/tag/value]">
      <xsl:value-of select="name()" />&LF;
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>
$ 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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