0

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

anky316
  • 21
  • 5
  • 1
    Please show us a sample of the input you want to process and the sample values you want to store in a variable. Also show us the XSLT you have tried. With `//*` you select all elements in a document, with `doc('tags.xml')/Tags/tag/value` you would select all `value` elements in the tag sample you have shown (assuming a file name `tags.xml') and then `//*[local-name() = doc('tags.xml')/Tags/tag/value]` selects all elements with a local name that is listed in the `tags.xml` document. – Martin Honnen Oct 13 '15 at 12:56
  • @Martin Honnen Hi, I have an xml which has a list of tags. CustomerLookup RefrenceNumber where CustomerLokup and RefrenceNumber are tag names. I want to check if any of these tags are available in the incoming request(Random xml requests). If any of the tag is present than Encrpyt that tag and send the original incoming xml with the encrypted tag forward. Thanks – anky316 Oct 14 '15 at 11:59
  • Well you have already shown one snippet in your question. If you want to add further snippets then edit your question and mark them up properly. And show us a sample of `random.xml` and how it is supposed to look once the tags have been encrypted so that we know what output you want to create. – Martin Honnen Oct 14 '15 at 12:03

1 Answers1

0

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>
$ 
HermannSW
  • 161
  • 1
  • 8