|
I'm trying to iterate the namespace declarations in an XML document so I can add them to the XmlNamespaceManager, but it's not working.
Given an XML document like:
<foo:bar xmlns:foo='the URI for foo' />
I expect:
System.Xml.XmlDocument doc = new System.Xml.XmlDocument() ;
doc.Load ( args [ 0 ] ) ;
System.Xml.XmlNamespaceManager mgr = new System.Xml.XmlNamespaceManager ( doc.NameTable ) ;
foreach ( System.Xml.XmlNode nod in doc.SelectNodes ( "//*[@xmlns:*]" , mgr ) )
...
to select that element, but it doesn't.
Am I missing something? Does SelectNodes just not want to select by namespace attributes?
Edit: I now see that this is the defined behaviour of XPath 1.0; I don't like it, but there it is.
modified 29-Mar-12 18:00pm.
|
|
|
|
|
Kinda sounds like you're putting the cart before the horse. You're trying to walk the document to select the namespaces, but in order to walk the tree with xpaths, you really need the namespaces first. Do you not know the structure of your XML? You're really supposed to know your namespaces first, and just use them.
You can, I think, walk the tree through the object model and pull out the namespace prefixes and URIs--using some combination of the NamespaceURI property, and the GetNamespaceOfPrefix and/or GetPrefixOfNamespace methods. There's probably a much more efficient way, though--maybe the XMLReader? Quick search .. try this:
http://www.hanselman.com/blog/GetNamespacesFromAnXMLDocumentWithXPathDocumentAndLINQToXML.aspx[^]
|
|
|
|
|
woopsydoozy wrote: Do you not know the structure of your XML?
Correct.
woopsydoozy wrote: in order to walk the tree with xpaths, you really need the namespaces
I know the one for xmlns, and it's in the manager, but I can't use it.
I'll read the suggested page. Thanks.
|
|
|
|
|
Having read the suggested page and tried a few more things I now understand a lot more about the problems I'm having, but it still doesn't explain why I can't use SelectNodes to get the information I need.
|
|
|
|
|
Is your issue maybe in using the namespace in the xpath? In your original XML snippet, for example, if you wanted the "box" element in the foo namespace, you'd select foo:box. You do have to add the "foo" namespace to your manager to use it, though:
mgr.AddNamespace("foo","the URI for foo") Just declaring a namespacemanager does not automatically load all the namespaces.
When it's a default namespace (no prefix), the trick I've used in the past is to add a new namespace that has the same URI:
mgr.AddNamespace("foo2","the URI for foo") This allows me to query for foo2:box.
Or maybe you're just wondering why you can't query using xmlns as an attribute? I don't know the technical answer except that it's special somehow, not available as a standard attribute. You can still access it in xpath/xslt if you need to--check out the namespace-uri method, for example.
|
|
|
|
|
woopsydoozy wrote: Is your issue maybe in using the namespace in the xpath?
No, I got that now.
woopsydoozy wrote: Just declaring a namespacemanager does not automatically load all the namespaces
Right, and now I understand why. I hope to write at least a Tip on it soon.
woopsydoozy wrote: When it's a default namespace ...
Right, even though it seems bogus (I still need to investigate further).
Edit: The W3C spec for XPath 1.0 (section 2.3 Node tests) says in part:<br />
"<br />
A QName in the node test is expanded into an expanded-name using the namespace declarations from the expression context. This is the same way expansion is done for element type names in start and end-tags except that the default namespace declared with xmlns is not used: if the QName does not have a prefix, then the namespace URI is null (this is the same way attribute names are expanded). <br />
"<br />
<a href="http://www.w3.org/TR/xpath/#node-tests">http:
<br />
So it's W3C's fault and I still don't see why they would define it that way. :mad:<br />
woopsydoozy wrote: maybe you're just wondering why you can't query using xmlns as an attribute
Yes, and also as the namespace of an attribute.
<br />
Edit: The W3C spec for XPath 1.0 (section 5.3 Attribute Nodes) says in part:<br />
"<br />
There are no attribute nodes corresponding to attributes that declare namespaces <br />
"<br />
modified 29-Mar-12 17:22pm.
|
|
|
|
|
Michael Kay rocks (check out his books, if you're doing anything with XSLT): http://www.stylusstudio.com/xsllist/200403/post30310.html
And attributes don't inherit the namespaces of their containing element by default. They only have namespaces if they have their own namespace prefix (which I don't think I've ever seen in practice). So if you had this XML:
<demo xmlns:foo='foo URI'><foo:box contents='zombie cat'/></demo>
and you wanted to find out what was in the box, you'd add foo and its URI to your namespace manager and get /demo/foo:box/@contents. Only with this XML:
<demo xmlns:foo='foo URI'><foo:box foo:contents='zombie cat'/></demo>
would you need to specify the attribute's namespace: /demo/foo:box/@foo:contents.
|
|
|
|
|
Thanks, I'll have to look into some books.
The rest of that I understand, but it still remains that when there's a namespace attribute, like:
<foo:bar xmlns:foo='foo' />
I can't select it even though the namespace is in the manager.
I really suspect that MS made some controversial choices in implementing System.Xml.XPath.XPathNavigator.Select when it comes to the default namespace and the xmlns namespace. So I may have to implement my own and I don't look forward to it.
|
|
|
|
|
Hello All,
I want to return a set of nodes where the value of my ID attribute falls within a specified range. i.e. if I have 200 elements with each elements' ID being sequential I would like to return N of them where the @ID >= X and @ID <= Y. But regardless of how I try to do this I end up with nothing! For example :
/element[@ID >= '44' and following-sibling[@ID <= '50']
Ideally this would return 6 elements but I get nothing, nor does :
/input[@ID >= '44' and following-sibling[@ID <= '50']]
I would appreciate your help on this please, it's driving me to distraction.
--
Moo
|
|
|
|
|
you're over-thinking it:
element[@ID >= '44' and @ID <= '50']
|
|
|
|
|
Of course! Thank you.
--
Moo
|
|
|
|
|
|
Validation failed!!!
"GET OUT OF HERE" was the message
Every new day is another chance to change your life.
|
|
|
|
|
Hi all
I have a php page with is connected to a xml file to display the data, for some reason this data will not display it will only dispplay the header and footer, i have worked out there has to be something wrong with the products.php as when i use a problem called xlm notepad and open the xml and attach the XLST or XLS it will display in the text window
if someone could please tell me how to get this fixed as i need to get it fixed asap
here is the code for the product.php
<!--
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Products - Australian Financial and Mortgage Services </title>
<meta http-equiv="content-script-type" content="text/javascript" >
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" >
<link href="settings.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="container"><!--
<div id= "ptitle">PRODUCTS AND SERVICES</div>
<?php include("menu.php"); ?>
<?php
$xp = new XsltProcessor();
$xsl = new DomDocument;
$xsl->load('products.xsl');
$xp->importStylesheet($xsl);
$xml_doc = new DomDocument;
$xml_doc->load('products.xml');
$xp->setParameter('', 'product', 1);
if ($html = $xp->transformToXML($xml_doc)) {
echo $html;
} else {
trigger_error('XSL transformation failed.', E_USER_ERROR);
} ?>
<!--
<?php include("footer.php"); ?>
<!--
<!--
</div>
</body>
</html>
this is the code for the products.xml
<products>
<product cat-ref="HL" id="HL01">
<title lang="en">Standard Variable</title>
<Description>
<p>
"Standard Variable"
A standard variable loan offers the customer freedom of choice with complete
repayment flexibility and a full range of features. <br/> The interest rate on these
types of loans fluctuates (up or down) as interest rates change in our financial
markets.</p>
<list type="numbered">
<list-intro>There are additional benefits associated with a standard variable
loan:</list-intro>
<list-item>Flexibility to choose between interest only repayments or principal and
interest repayments.</list-item>
<list-item>Redraw facility is available and you can utilise this option to redraw
payments already made in advance.</list-item>
<list-item>You can have a partial or 100% interest offset facility attached to your
loan when the loan includes repayments for principal and interest. Interest
offset is not available on interest only loans.</list-item>
<list-item>Principal reduction may be made at any time without attracting additional
fees.</list-item>
<list-item>You also have the option of taking the loan over a maximum of 30 years
but you can opt to repay your loan in full within a shorter period of time
without attracting additional penalty charges.</list-item>
<list-item>Clients can make as many additional payments to their standard variable
loan as they wish.</list-item>
</list>
<p>It is important to note that lenders may have other associated costs to cover
administration fees. Our consultants can compare these facilities and ensure that
the appropriate loan structure is put in place to help you achieve your financial
needs.<br/></p>
</Description>
</product>
<product cat-ref="HL" id="HL02">
<title lang="en">Basic Variable</title>
<Description>
Basic Variable
<p>Basic variable rate loans are sometimes referred to as the 'no frills' alternative to the standard
variable rate loans. The interest rate is lower than a standard variable loan, making them attractive
to the budget conscious borrower. It offers a lower variable rate but with fewer features. These loans
normally have no ongoing fees associated with it.</p>
</Description>
</product>
<product cat-ref="HL" id="HL03">
<title lang="en">Introductory (Honeymoon)</title>
<Description>
Introductory (Honeymoon)
<p>An Introductory Variable Rate loan generally offers a guaranteed low rate for an initial period of
time (usually 12 months) after which most interest rates will revert to the Standard Variable Rate.
It is Ideal for those wishing to take advantage of lower initial repayments.</p>
</Description>
</product>
<product cat-ref="HL" id="HL04">
<title lang="en">Fixed Rate Loan</title>
<Description>
Fixed Rate Loan
<p>Fixed rate loans are funds lent over a set term at a set interest rate. This gives the borrower
the certainty of knowing exactly what their monthly repayments will be should their circumstances change.
Some lenders may impose early repayment penalties if you make a lump sum reduction to your loan or you pay
the loan out in full. However, a fixed rate loan is ideal in a rising interest rate market as this guarantees
you of your interest rate and repayments for a set time.</p>
</Description>
</product>
<product cat-ref="HL" id="HL05">
<title lang="en">Refinancing</title>
<Description>
Refinancing
<p>Mortgage refinancing is a process of renegotiating your original mortgage agreement. </p>
<p>With the lending sector constantly changing and lenders constantly enhancing their products to attract new customers, existing customers are left behind, often with products that are no longer as well placed in the market as they once were. It is always important to keep an eye on how your mortgage stacks up against current market leaders and having a mortgage broker can simplify this for you.</p>
<p>While there are inherent costs in altering your existing mortgage you must compare these to the savings made over the entire term of your loan.</p>
</Description>
</product>
<product cat-ref="HL" id="HL06">
<title lang="en">Bridging Loan</title>
<Description>
Bridging Loan
<p>A Bridging Loan is available to borrowers who wish to purchase a new home now and sell your current home later.
These loans are especially helpful to 'bridge' the gap between the sale of one property and the purchase of another.
The interest rate on a Bridging Home Loan is usually the same as a Standard Variable Rate Loan. A Bridging Loan ensures
that the borrower will not miss out on a desired property because they haven't sold the current home</p>
</Description>
</product>
<product cat-ref="NCL" id="NCL02">
<title lang="en">Credit Impaired</title>
<Description>
<p>Low Documentation (or No documentation) loans are designed for the self-employed or small company borrower whose financial statements may not be available for many different reasons (eg Accountant hasn't completed their financials). The borrower must have a sizeable deposit or equity in existing real estate property. Generally, most lenders lend a maximum of 80% of the property value with mortgage insurance applying above 60%.</p>
<p>These loans are usually a variable rate and offer most of the features and benefits attached to the lender's standard variable rate loan product. A Low Document Loan can be just as competitive as a full documentation loan, however they provide less hassle as the borrower doesn't have to provide the lender income documentation.</p>
</Description>
</product>
<product cat-ref="NCL" id="NCL03">
<title lang="en">Low Document Loans</title>
<Description>
<p>At some point in the past, a borrower may have experienced difficulty in meeting their monthly commitments due to lack of work, suffered unexpected business losses or had a difference of opinion with a former credit provider. Unfortunately, in these cases the former credit provider may have lodged a payment default (or black mark) on their credit report with a credit recording agency. When applying for finance, a default lodged on a credit report may cause some frustration as a lender may not take an understanding view of the borrower’s explanation surrounding the default.</p>
</Description>
</product>
<product cat-ref="NCL" id="NCL04">
<title lang="en">Second Mortgages</title>
<Description>
<p>Second Mortgages</p>
<p>A second mortgage is an additional loan on a property. Second mortgages usually carry a higher interest charge as the first mortgage carries first priority in the case of default. The second mortgage also carries rights to the property, but these are subordinate to those of the first mortgage. In the case of approving a client for a second mortgage, the lender will calculate the affordability and risk of the first mortgage before calculating whether you would be able to meet any additional repayments.</p>
</Description>
</product>
<product cat-ref="CEL" id="CEL01">
<title lang="en">Hire Purchase</title>
<Description>
<p>Hire Purchase</p>
<p>The Hire Purchase Agreement is simply a contract where the lender allows the client the right to possess and use an item of equipment in return for regular payments. When the final payment is made, the title of the goods is transferred to the customer. This product is designed for businesses wishing to finance the purchase of motor vehicles and trucks, industrial plant and equipment, business and professional equipment.
Features and benefits include:</p>
<list type="numbered">
<list-intro>Features and benefits include:</list-intro>
<list-item>Repayment schedules can be structured to suit a customer’s cash flow.</list-item>
<list-item>Can be arranged with no deposit or an amount that suits the customer.</list-item>
<list-item>Flexible repayments allow for accurate capital budgeting..</list-item>
<list-item>Balloon payments at the end of the term can be arranged</list-item>
<list-item>Client gains automatic ownership at end of term..</list-item>
<list-item>Interest and depreciation are tax deductible if business expense.</list-item>
<list-item>Client can repay the contract before the term ends.</list-item>
</list>
</Description>
</product>
<product cat-ref="CEL" id="CEL02">
<title lang="en">Finance Lease</title>
<Description>
<p>Finance Lease</p>
<p>Here the lender purchases the plant, equipment or vehicle required by the client (the lessee). The lender then leases the goods to the customer under a lease agreement.
When the lease expires the lessee can either:.</p>
<list type="numbered">
<list-intro>There are additional benefits associated with a standard variable
loan:</list-intro>
<list-item>Return the equipment to the lender who can sell it elsewhere. If the net sale is less than the residual value, the customer must make up the shortfall.</list-item>
<list-item>Refinance the residual value.</list-item>
<list-item>Pay out the contract.</list-item>
<list-item>Make an offer to purchase, which may be accepted by the lender..</list-item>
</list>
</Description>
</product>
<product cat-ref="BF" id="BF01">
<title lang="en">Commercial Mortgages</title>
<Description>
<b>Commercial Mortgages</b>
<p>A commercial mortgage is similar to a regular residential loan except that the loan is applied to a purchase of commercial property. Commercial property generally includes retail shops or offices, warehouses and factory units.</p>
<p>Commercial mortgages are handled the same way as regular residential mortgages in that lenders want to ensure that their money will be making them more money. They will want to certify that the property being targeted is worth their investment and that the borrower’s credentials are trustworthy.</p>
<p>If you are looking to acquire a commercial mortgage the first thing to do is put together a package detailing the potential of the property your want to buy. If possible you should do a little market research that demonstrates the property’s main selling points such as: if it is in a high traffic area, if it is easily accessible, etc… any feature that will make it more attractive in the eyes of a lender, whose main goal is to know that he or she will not lose money on this deal.</p>
<p>Finding the right lender is the next step and that is where we come in. We do more than just find the right lender for their clients; we also offer support, information and advice. Commercial property can be a great investment if well located and properly managed.</p>
</Description>
</product>
<product cat-ref="BF" id="BF02">
<title lang="en">Short Term Business Loans</title>
<Description>
<b><u>Short Term Business Loans</u></b>
<p>From time to time business or investors find themselves in a situation where they need funds to get them through a short term slump, or to take advantage of a lucrative investment opportunity that presents itself. The business or investor may not be able to access normal loan funds in time to ward off financial difficulties or to take advantage of the opportunity that has presented itself. In both cases short term business loans may be the answer. Short term business loans are for business purposes only and usually the term is measured in months rather than years. The rate is much higher than normal business loans, (3%-10% per month are standard) but are usually easy and quick to obtain. These are pure asset lends with a maximum LVR of 80%. As it is a straight asset lend, credit checks and financials are not usually required.</p>
</Description>
</product>
<product cat-ref="BF" id="BF03">
<title lang="en">Medium-Long Term Business Loans</title>
<Description>
<b><u>Medium-Long Term Business Loans</u></b>
<p>Many bank lenders charge hefty interest rate penalties for their business purpose loans. A surcharge of 1-2 percent is not uncommon and some overdraft rates are in excess of 12%. Non bank lenders are able to provide business purpose loans at the same rate as owner occupied home loan rates. If you need money for business purposes, why get ripped off by the banks when you can access the equity in your home or investment property at rates well below 7%.</p>
</Description>
</product>
<product cat-ref="IP" id="IP01">
<title lang="en">Why is an Investment Property a Good Strategy ?</title>
<Description>
<b><u>Why is an Investment Property a Good Strategy ?</u></b>
<p>Most people like property because they can see it, touch it and watch it grow in value over a period of time. If bought in the right area (location), it can offer good returns in capital growth in future years. Also, the depreciation, coupled with rental income, makes this method an easy way to get into property and make it an attractive proposition.</p>
<p>If you already own a property it makes getting into an investment property much easier as you can use the equity in your home as a deposit towards an investment property.</p>
</Description>
</product>
<product cat-ref="IP" id="IP02">
<title lang="en">Negative Gearing</title>
<Description>
<b><u>Negative Gearing</u></b>
<p>Negative Gearing is the situation when an investment such as property is purchased with the assistance of borrowed funds and where the rental income after the deduction of expenses (such as interest, bank fees, insurance and strata fees) is less than the interest commitment in the course of a financial year.</p>
<p>For tax purposes this negative net income can then be offset against any positive income from other sources. This is a very handy tool in minimizing tax.</p>
</Description>
</product>
<product cat-ref="IP" id="IP03">
<title lang="en">Capital Gains Tax</title>
<Description>
<b><u>Capital Gains Tax</u></b>
<p>Capital gains are the profits made on selling assets. Your primary place of residence is exempt from any capital gains tax. An investment property sold at a profit will attract a capital gains tax on the profit. The amount will be added to your regular income and taxed at your marginal rate. However, depending on your situation at the time of selling a property, the capital gains tax could be adjusted to be reduced by way of new investments put in place. You should get advice on this matter before selling so that you can structure it correctly.</p>
</Description>
</product>
<product cat-ref="OP" id="OP01">
<title lang="en">Line of Credit</title>
<Description>
<b><u>Line of Credit</u></b>
<p>A Line of Credit provides a borrower with access to the equity in their home or investment properties whenever they wish for any worthwhile purpose. It is similar to an overdraft facility in that funds can be withdrawn up to the original loan approved amount at anytime. The interest rate on a Line of Credit facility is usually a variable rate that fluctuates with the market. A borrower can generally access their Line of Credit via a Cheque Book, Credit Card, ATM, Phone and Internet. A Line of Credit provides a borrower with easy access to funds ensuring peace of mind in times of need.</p>
</Description>
</product>
<product cat-ref="OP" id="OP02">
<title lang="en">Reverse Mortgages</title>
<Description>
<b><u>Reverse Mortgages</u></b>
<p>Unlike conventional mortgage products reverse mortgages (also known as equity release), focus exclusively on a specific segment of the population: retirees. They allow retiring homeowners to access a largely untapped asset to fund a standard of living that for many would otherwise be out of reach.
Reverse mortgages are similar to conventional residential mortgages in that the borrower raises funds against the security of the home. However, reverse mortgages are very different to conventional mortgages when it comes to drawdown, cash flow, and repayments.</p>
<p>In a normal mortgage, the principal amount of the loan is generally advanced as a lump sum to the borrower in order to a purchase a property. The borrower must then make regular principal and interest payments during the term of the loan. If the borrower defaults on the loan, the lender may recover the outstanding balance of the loan (including any unpaid interest) by enforcing its mortgage and selling the mortgaged home.
That is not the case with a reverse mortgage. In addition to having the option of receiving the principal in an upfront lump sum payment, the retiree can also choose to receive the principal in the form of regular part-payments from the lender during the term of the loan.
The retiree is not required to make any repayments (whether of principal or interest) to the lender during the term of the loan, however in some cases may have the option to do so. Instead, the entire loan (including accrued interest) falls due on the death of the retiree, or when the retiree moves out of the mortgaged home permanently, for example into a nursing home or if the property is sold.</p>
<p>The lender then recovers the loan by either having the beneficiaries of the retiree's estate pay the debt, or by enforcing its mortgage and selling the mortgaged home. In most cases, the lender will give the retiree's beneficiaries up to six months to finalise the debt. If the lender sells the property, they will give any funds left over to the estate of the retiree</p>
</Description>
</product>
<categories>
<category cat-id="HL">Home Loans</category>
<category cat-id="NCL">Non-conforming Loans</category>
<category cat-id="CEL">Car/Equipment Loans</category>
<category cat-id="BF">Business Finance</category>
<category cat-id="IP">Investment Property</category>
<category cat-id="OP">Other Loans</category>
</categories>
</products>
this is the code for the products.xsl
="1.0"="UTF-8"
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:key name="product-by-cat" match="product" use="@cat-ref"/>
<xsl:key name="product-by-id" match="product" use="@id"/>
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:param name="product"/>
<xsl:param name="base-page" select="'product.php'"/>
<xsl:template match="products">
<div id="productsdesc">
<xsl:if test="normalize-space($product)">
<xsl:apply-templates select="key('product-by-id', $product)/Description"/>
</xsl:if>
</div>
<div id="products">
<table>
<xsl:for-each select="categories/category[position() mod 3 = 1]">
<tr>
<th><xsl:apply-templates select="."/></th>
<th><xsl:apply-templates select="following-sibling::category[1]"/></th>
<th><xsl:apply-templates select="following-sibling::category[2]"/></th>
</tr>
<xsl:call-template name="get-next-row">
<xsl:with-param name="cat1" select="@cat-id"/>
<xsl:with-param name="cat2" select="following-sibling::category[1]/@cat-id"/>
<xsl:with-param name="cat3" select="following-sibling::category[2]/@cat-id"/>
<xsl:with-param name="count" select="1"/>
</xsl:call-template>
</xsl:for-each>
</table>
</div>
</xsl:template>
<xsl:template name="get-next-row">
<xsl:param name="cat1"/>
<xsl:param name="cat2"/>
<xsl:param name="cat3"/>
<xsl:param name="count"/>
<xsl:if test="key('product-by-cat', $cat1)[position() = $count ]| key('product-by-cat', $cat2)[position() = $count] | key('product-by-cat', $cat3)[position() = $count]">
<tr>
<td><a href="{concat($base-page, '?product=', key('product-by-cat', $cat1)[position() = $count ]/@id)}"><xsl:apply-templates select="key('product-by-cat', $cat1)[position() = $count ]/title"/></a></td>
<td><a href="{concat($base-page, '?product=', key('product-by-cat', $cat2)[position() = $count ]/@id)}"><xsl:apply-templates select="key('product-by-cat', $cat2)[position() = $count ]/title"/></a></td>
<td><a href="{concat($base-page, '?product=', key('product-by-cat', $cat3)[position() = $count ]/@id)}"><xsl:apply-templates select="key('product-by-cat', $cat3)[position() = $count ]/title"/></a></td>
</tr>
<xsl:call-template name="get-next-row">
<xsl:with-param name="cat1" select="$cat1"/>
<xsl:with-param name="cat2" select="$cat2"/>
<xsl:with-param name="cat3" select="$cat3"/>
<xsl:with-param name="count" select="$count + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="p">
<p>
<xsl:apply-templates select="node()"/>
</p>
<br/>
</xsl:template>
<xsl:template match="list">
<p class="list_intro">
<xsl:apply-templates select="list-intro"/>
</p>
<br/>
<ol>
<xsl:for-each select="list-item">
<li><xsl:apply-templates/></li>
</xsl:for-each>
</ol>
</xsl:template>
</xsl:stylesheet>
this is the code for the products.xlst
="1.0"="UTF-8"
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:key name="product-by-cat" match="product" use="@cat-ref"/>
<xsl:key name="product-by-id" match="product" use="@id"/>
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:param name="product"/>
<xsl:param name="base-page" select="'../product.php'"/>
<xsl:template match="products">
<div id="productsdesc">
<xsl:if test="normalize-space($product)">
<xsl:apply-templates select="key('product-by-id', $product)/Description"/>
</xsl:if>
</div>
<div id="products">
<table>
<xsl:for-each select="categories/category[position() mod 3 = 1]">
<tr>
<th><xsl:apply-templates select="."/></th>
<th><xsl:apply-templates select="following-sibling::category[1]"/></th>
<th><xsl:apply-templates select="following-sibling::category[2]"/></th>
</tr>
<xsl:call-template name="get-next-row">
<xsl:with-param name="cat1" select="@cat-id"/>
<xsl:with-param name="cat2" select="following-sibling::category[1]/@cat-id"/>
<xsl:with-param name="cat3" select="following-sibling::category[2]/@cat-id"/>
<xsl:with-param name="count" select="1"/>
</xsl:call-template>
</xsl:for-each>
</table>
</div>
</xsl:template>
<xsl:template name="get-next-row">
<xsl:param name="cat1"/>
<xsl:param name="cat2"/>
<xsl:param name="cat3"/>
<xsl:param name="count"/>
<xsl:if test="key('product-by-cat', $cat1)[position() = $count ]| key('product-by-cat', $cat2)[position() = $count] | key('product-by-cat', $cat3)[position() = $count]">
<tr>
<td><a href="{concat($base-page, '?product=', key('product-by-cat', $cat1)[position() = $count ]/@id)}"><xsl:apply-templates select="key('product-by-cat', $cat1)[position() = $count ]/title"/></a></td>
<td><a href="{concat($base-page, '?product=', key('product-by-cat', $cat2)[position() = $count ]/@id)}"><xsl:apply-templates select="key('product-by-cat', $cat2)[position() = $count ]/title"/></a></td>
<td><a href="{concat($base-page, '?product=', key('product-by-cat', $cat3)[position() = $count ]/@id)}"><xsl:apply-templates select="key('product-by-cat', $cat3)[position() = $count ]/title"/></a></td>
</tr>
<xsl:call-template name="get-next-row">
<xsl:with-param name="cat1" select="$cat1"/>
<xsl:with-param name="cat2" select="$cat2"/>
<xsl:with-param name="cat3" select="$cat3"/>
<xsl:with-param name="count" select="$count + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="p">
<p>
<xsl:apply-templates select="node()"/>
</p>
<br/>
</xsl:template>
<xsl:template match="list">
<p class="list_intro">
<xsl:apply-templates select="list-intro"/>
</p>
<br/>
<ol>
<xsl:for-each select="list-item">
<li><xsl:apply-templates/></li>
</xsl:for-each>
</ol>
</xsl:template>
</xsl:stylesheet>
thank you all for your help in advance
|
|
|
|
|
hi guys.i want to generate html tree from xml file using xslt.. how can i do tht.. i have tried plenty of examples from net.. but didnt get the correct.. code... plz reply.. regards,
|
|
|
|
|
How to open Zip file and Xls files
|
|
|
|
|
In what language, for what purpose?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Double-click on it.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Hi,
I am trying to implement Apriori Algorithm(Mining Association Rules from XML Data) with XQuery. Unfortunately, I am not familiar with XQuery language. So, I need your help to fix the bug in the code given below
xquery version "1.0";
declare function apriori($l, $L, $minsup, $total, $src)
{
let $C := removeDuplicate(candidateGen($l))
let $l := getLargeItemsets($C, $minsup, $total, $src)
let $L := $l union $L
return if (empty($l)) then
$L
else
apriori($l, $L, $minsup, $total, $src)
}
let $src := doc(/transactions.xml)//items
let $minsup := 0.4
let $total := count($src) * 1.00
let $C := distinct-values($src/*)
let $l :=(for $itemset in $C
let $items := (for $item in $src/*
where $itemset = $item
return $item)
let $sup := (count($items) * 1.00) div $total
where $sup >= $minsup
return <largeItemset>
<items> {$itemset} </items>
<support> {$sup} </support>
</largeItemset>)
let $L := $l
return <largeItemsets> {apriori($l, $L,$minsup, $total, $src)}
</largeItemsets>
Error:
[DataDirect][XQuery][err:XPST0003]Error at line 14, column 1. Expected ";", but encountered "let"
Thanks for any help
|
|
|
|
|
Hi,
My Sample XML is as follows:
<Students>
<Student>
<roll id="1" />
<StudName id="stud1" />
<Class1 val="cls1" />
<Class2 val="cls2" />
<Class3 val="cls3" />
<Class4 val="cls4" />
<Class5 val="cls5" />
<Class6 val="cls6" />
</Student>
<Student>
<roll id="2" />
<StudName id="stud2"/>
<Class1 val="cls7" />
<Class2 val="cls8" />
<Class3 val="cls9" />
<Class4 val="cls10" />
<Class5 val="cls11" />
<Class6 val="cls12" />
</Student>
<Student>
<roll id="3" />
<StudName id="stud3" />
<Class1 val="cls13" />
<Class2 val="cls14" />
<Class3 val="cls15" />
<Class4 val="cls16" />
<Class5 val="cls17" />
<Class6 val="cls18" />
</Student>
<Student>
<roll id="4" />
<StudName id="stud4" />
<Class1 val="cls19" />
<Class2 val="cls20" />
<Class3 val="cls21" />
<Class4 val="cls22" />
<Class5 val="cls23" />
<Class6 val="cls24" />
</Student>
<Student>
<roll id="5" />
<StudName id="stud5" />
<Class1 val="cls25" />
<Class2 val="cls26" />
<Class3 val="cls27" />
<Class4 val="cls28" />
<Class5 val="cls29" />
<Class6 val="cls30" />
</Student>
</Students>
Now i need to prepare XSLT such that if nodes are more than 3 then i need to get only roll and studname nodes.
I need to get the result as
<Students>
<Student>
<roll id="1" />
<StudName id="stud1" />
</Student>
<Student>
<roll id="2" />
<StudName id="stud2"/>
</Student>
<Student>
<roll id="3" />
<StudName id="stud3" />
</Student>
<Student>
<roll id="4" />
<StudName id="stud4" />
</Student>
<Student>
<roll id="5" />
<StudName id="stud5" />
</Student>
</Students>
Please provide me the required XSLT such that i need to get the above output...
Thanks in advance
Harini
|
|
|
|
|
I don't understand;
harinit wrote: if nodes are more than 3
From your input and output it looks as if you are doing nothing more than removing all the ClassX nodes.
Every man can tell how many goats or sheep he possesses, but not how many friends.
|
|
|
|
|
Hi i am sorry for not explaining correctly...
My sample xml is as follows:
<Students>
<Student>
<roll id="1" />
<StudName id="stud1" />
<Class1 val="cls1" />
<Class2 val="cls2" />
<Class3 val="cls3" />
<Class4 val="cls4" />
<Class5 val="cls5" />
<Class6 val="cls6" />
</Student>
<Student>
<roll id="2" />
<StudName id="stud2"/>
<Class1 val="cls7" />
<Class2 val="cls8" />
<Class3 val="cls9" />
<Class4 val="cls10" />
<Class5 val="cls11" />
<Class6 val="cls12" />
</Student>
<Student>
<roll id="3" />
<StudName id="stud3" />
<Class1 val="cls13" />
<Class2 val="cls14" />
<Class3 val="cls15" />
<Class4 val="cls16" />
<Class5 val="cls17" />
<Class6 val="cls18" />
</Student>
<Student>
<roll id="4" />
<StudName id="stud4" />
<Class1 val="cls19" />
<Class2 val="cls20" />
<Class3 val="cls21" />
<Class4 val="cls22" />
<Class5 val="cls23" />
<Class6 val="cls24" />
</Student>
<Student>
<roll id="5" />
<StudName id="stud5" />
<Class1 val="cls25" />
<Class2 val="cls26" />
<Class3 val="cls27" />
<Class4 val="cls28" />
<Class5 val="cls29" />
<Class6 val="cls30" />
</Student>
</Students>
We need to get the length of xml node including child nodes.
Suppose if the length of xml exceeds the configured length then it should be formatted as small xml file with root elements.
Example: consider the <student> node(including child nodes) exceedes the length 100 then we should format the xml as given below using XSLT.
<Students>
<Student>
<roll id="1" />
<StudName id="stud1" />
<Class1 val="cls1" />
<Class2 val="cls2" />
<Class3 val="cls3" />
<Class4 val="cls4" />
<Class5 val="cls5" />
<Class6 val="cls6" />
</Student>
</Students>
<Students>
<Student>
<roll id="2" />
<StudName id="stud2"/>
<Class1 val="cls7" />
<Class2 val="cls8" />
<Class3 val="cls9" />
<Class4 val="cls10" />
<Class5 val="cls11" />
<Class6 val="cls12" />
</Student>
</Students>
|
|
|
|
|
="1.0"="utf-8"
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="Students">
<Students>
<xsl:for-each select="*">
<xsl:choose>
<xsl:when test="count(./*) > 3">
<Student>
<xsl:copy-of select="roll"/>
<xsl:copy-of select="StudName"/>
</Student>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</Students>
</xsl:template>
</xsl:stylesheet>
|
|
|
|
|
Dear readers,
for an xml-file I creat the corresponding schema-file (.xsd) in two ways: a) with VStudio and b) with the tool "xsd.exe"
Both results are in some way different. e.g. at data-types or at the label "minoccurs". It seems not to be so dramatic.
But, I use these schema-files for xmlmaps in excel, and here I have a dramatic impact. I get totally different behavior for both xsd-version.
Does anybody know, why both tools give a different result?
For my use-case, the VStudio-generated xsd is better, but how can I access is without Vstudio?
Thanks in advance
|
|
|
|
|
How do i check if a certain value exists?
For example, if my document looks like this:
<Systems>
<systemData>
<name>Name1</name>
<status>Active</status>
<slot>0</slot>
</systemData>
<systemData>
<name>Name2</name>
<status>Active</status>
<slot>1</slot>
</systemData>
</Systems>
how would i query the document to see if "Name1" exists?
|
|
|
|
|