Hello, first post here so take it easy :)

I have been searching with no luck on finding a solution - hopefully you can help!

I need to reference a xml file and get the value of an element. In my initial xml post, I will send along an ip address, this ip address will be set as a variable in my xsl transform. I need to use that variable to be used to reference the element on the xml document.

sample xml (IP to Alias lookup):

<servers>
	<ip id="172.22.17.79">
		<server>myServer1</server>
	</ip>
	<ip id="172.22.17.80">
		<server>myServer2</server>
	</ip>
	<ip id="172.22.17.81">
		<server>myServer3</server>
	</ip>
</servers>

xsl transform

<!--this is the variable set from my xml post -->
<xsl:variable name="server1ip" select="/config/server1ip"/>  
<!-- this is the variable that references the servers.xml doc -->
<xsl:variable name="server1ipLU" select="document('servers.xml')"/>
<!--this is the select I am having issues with - I need it to return the server value value -->
<xsl:value-of select="$server1ipLU/servers[@ip=$server1ip]/server"/>

Let me know if you need more information, I appreciate the help!

-David

@ip=$server1ip

ip is a node, NOT an attribute.

for testing purposes try: select="document('servers.xml')/servers/ip[@id='172.22.17.80']"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.