So, what I want to be able to do, is query an XML file using xsltproc, passing in a parameter for the NAME of the server. This name is contained within the XML document. I want to pull the username and password from this file.So, the Name is a sibling of the User and Pass. I don't use XSLT or XPath or XQuery all that often (this is the second time in 19 years now). I'm just lost on how to pull the data from the XML file from the stylesheet.Here's what I'm passing in from the CLI (I think it's right):
\[code\]xsltproc --stringparam site_name "'site2'" style.xsl source.xml\[/code\]Here's the XML\[code\]<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><Container> <Servers> <Folder expanded="1"> <Server> <User>username1</User> <Pass>password1</Pass> <Name>Site1</Name> </Server> <Server> <User>username2</User> <Pass>password2</Pass> <Name>Site2</Name> </Server> </Folder> <Server> <User>username3</User> <Pass>password3</Pass> <Name>Site3</Name> </Server> <Server> <User>username4</User> <Pass>password4</Pass> <Name>Site4</Name> </Server> </Servers></Container>\[/code\]Here's my current XSLT Stylesheet\[code\]<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xslaram name="site_name">Site1</xslaram> <xslutput method="text"/> <xsl:template match="//Servers"> <xsl:value-of select="//Server/Name"/> </xsl:template></xsl:stylesheet>\[/code\]
\[code\]xsltproc --stringparam site_name "'site2'" style.xsl source.xml\[/code\]Here's the XML\[code\]<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><Container> <Servers> <Folder expanded="1"> <Server> <User>username1</User> <Pass>password1</Pass> <Name>Site1</Name> </Server> <Server> <User>username2</User> <Pass>password2</Pass> <Name>Site2</Name> </Server> </Folder> <Server> <User>username3</User> <Pass>password3</Pass> <Name>Site3</Name> </Server> <Server> <User>username4</User> <Pass>password4</Pass> <Name>Site4</Name> </Server> </Servers></Container>\[/code\]Here's my current XSLT Stylesheet\[code\]<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xslaram name="site_name">Site1</xslaram> <xslutput method="text"/> <xsl:template match="//Servers"> <xsl:value-of select="//Server/Name"/> </xsl:template></xsl:stylesheet>\[/code\]