duw Posted May 18, 2014 at 12:20 PM Report #556150 Posted May 18, 2014 at 12:20 PM Boas, Surgiu-me uma problema que não consigo resolver. Eis a descrição do problema: XML1 (short.xml): <Employees> <HumanResources.Employee> <BusinessEntityID>1</BusinessEntityID> <NationalIDNumber>295847284</NationalIDNumber> <IDLogin>adventure-works\ken0</IDLogin> <JobTitle>Chief Executive Officer</JobTitle> <BirthDate>1959-03-02</BirthDate> <MaritalStatus>S</MaritalStatus> <Gender>M</Gender> <HireDate>1999-02-15</HireDate> <Address>Rua de Soutelo-Mouriz n100, 4580-596</Address> <City>VN Famalicao</City> </HumanResources.Employee> <HumanResources.Employee> <BusinessEntityID>2</BusinessEntityID> <NationalIDNumber>295847285</NationalIDNumber> <IDLogin>adventure-works\ken1</IDLogin> <JobTitle>Chief Executive Officer</JobTitle> <BirthDate>1959-03-02</BirthDate> <MaritalStatus>S</MaritalStatus> <Gender>M</Gender> <HireDate>1999-02-15</HireDate> <Address>Rua de Soutelo-Mouriz n100, 4580-596</Address> <City>Vila Nova Famalicao</City> </HumanResources.Employee> <HumanResources.Employee> <BusinessEntityID>3</BusinessEntityID> <NationalIDNumber>295847286</NationalIDNumber> <IDLogin>adventure-works\ken3</IDLogin> <JobTitle>Chief Executive Officer</JobTitle> <BirthDate>1959-03-02</BirthDate> <MaritalStatus>S</MaritalStatus> <Gender>M</Gender> <HireDate>1999-02-15</HireDate> <Address>Rua de Soutelo-Mouriz n100, 4580-596</Address> <City>VNF</City> </HumanResources.Employee> </Employees> XML2 (normalize.xml): <root> <elem> <source>VNF</source> <target>Vila Nova de Famalicão</target> </elem> <elem> <source>Vila Nova Famalicao</source> <target>Vila Nova de Famalicão</target> </elem> <elem> <source>VN Famalicao</source> <target>Vila Nova de Famalicão</target> </elem> </root> XSLT : <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:variable name="xml" select="document('short.xml')"></xsl:variable> <xsl:variable name="norm" select="document('normalize.xml')"></xsl:variable> <xsl:template match="node()|@*"> <xsl:for-each select="$xml/Employees/HumanResources.Employee"> <xsl:for-each select="$norm/root/elem"> <xsl:if test="$xml/Employees/HumanResources.Employee/City/text()=$norm/root/elem/source/text()"> <xsl:value-of select="$norm/root/elem/target/text()"/> </xsl:if> </xsl:for-each> </xsl:for-each> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> </xsl:stylesheet> Resumidamente, queria uniformizar o elemento City de cada Employee, que poderá tomar os vários valores Source, substituindo pelo Target. Não sei se é possível, mas penso que faça sentido. Agradeço toda a ajuda. Obrigado
Rui Carlos Posted May 19, 2014 at 02:44 PM Report #556267 Posted May 19, 2014 at 02:44 PM Penso que é possível. Podes usar a função document para ler o XML com as substituições. É capaz de ser boa ideia usar o xsl:key para criares um map, que facilitará as substituições. Rui Carlos Gonçalves
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now