Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-05-2012, 06:36 AM   PM User | #1
hermanpeckel
New to the CF scene

 
Join Date: Aug 2012
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
hermanpeckel is an unknown quantity at this point
Variable Referencing via XPath

Folks,

After kicking an absolute goal on this forum last time (or having that goal kicked for me) I was hoping to get some more help with my latest XPath conundrum.

I need to reference the values of an XML variable in this code via an XPath -

Code:
<od:PageBoxInfo ID="Link6">
<Page>
<PageBox BoxType="MediaBox" Width="594.999" Height="1280"/>
<PageBox BoxType="CropBox" Width="594.999" Height="1280"/>
<PageBox BoxType="BleedBox" Width="594.999" Height="1280"/>
<PageBox BoxType="ArtBox" Width="594.999" Height="1280"/>
<PageBox BoxType="TrimBox" Width="594.999" Height="1280"/>
</Page>
</od:PageBoxInfo>
I'm trying to get the width of the MediaBox. I'm assuming it will be something like -

//od:PageBoxInfo/Page/PageBox/BoxType='MediaBox'/Width

...but, as I've mentioned before, I can barely spell XPath. Any help much appreciated!!

Thanks in advance
HP
hermanpeckel is offline   Reply With Quote
Old 09-10-2012, 03:47 AM   PM User | #2
Arbitrator
Senior Coder

 
Arbitrator's Avatar
 
Join Date: Mar 2006
Location: Splendora, Texas, United States of America
Posts: 2,900
Thanks: 5
Thanked 188 Times in 185 Posts
Arbitrator is on a distinguished road
Quote:
Originally Posted by hermanpeckel View Post
I'm trying to get the width of the MediaBox.
Given the XML:
Code:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="application/xml" href="master.xslt"?>
<od:PageBoxInfo ID="Link6" xmlns:od="http://www.codingforums.com/showthread.php?t=272271">
	<Page>
		<PageBox BoxType="MediaBox" Width="594.999" Height="1280"/>
		<PageBox BoxType="CropBox" Width="594.999" Height="1280"/>
		<PageBox BoxType="BleedBox" Width="594.999" Height="1280"/>
		<PageBox BoxType="ArtBox" Width="594.999" Height="1280"/>
		<PageBox BoxType="TrimBox" Width="594.999" Height="1280"/>
	</Page>
</od:PageBoxInfo>
You can get the relevant value with the following XSLT style sheet:

Code:
<?xml version="1.0" encoding="utf-8"?>
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:xslt="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<!-- |method="xml"| required for standards mode in Windows Internet Explorer 9.00.8112.16421 Update Versions 9.0.9 x64 -->
	<output method="xml" media-type="application/xhtml+xml"/>
	<template match="/">
		<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
			<head>
				<title>Demo Document</title>
				<style>
					/* Layout */
					* { margin: 0; padding: 0; }
					html, p { margin: 1em; }
				</style>
			</head>
			<body>
				<!-- Longform XPath Demo -->
				<p>The media box width is <xslt:value-of select="descendant-or-self::node()/child::PageBox[attribute::BoxType='MediaBox']/attribute::Width"/> units.</p>
				<!-- Shortform XPath Demo -->
				<p>The media box width is <xslt:value-of select="//PageBox[@BoxType='MediaBox']/@Width"/> units.</p>
			</body>
		</html>
	</template>
</stylesheet>
__________________
Please for the love of god stop making IE. You current "browser"s cause me to cry every day. —Phil *
Arbitrator is offline   Reply With Quote
Users who have thanked Arbitrator for this post:
hermanpeckel (09-27-2012)
Reply

Bookmarks

Tags
referencing, variables, xml, xpath

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:08 PM.


Advertisement
Log in to turn off these ads.